Module | Delayed::Backend::Base::ClassMethods |
In: |
lib/delayed/backend/base.rb
|
Hook method that is called after a new worker is forked
# File lib/delayed/backend/base.rb, line 37 37: def after_fork 38: end
Hook method that is called before a new worker is forked
# File lib/delayed/backend/base.rb, line 33 33: def before_fork 34: end
Add a job to the queue
# File lib/delayed/backend/base.rb, line 13 13: def enqueue(*args) 14: object = args.shift 15: unless object.respond_to?(:perform) 16: raise ArgumentError, 'Cannot enqueue items which do not respond to perform' 17: end 18: 19: priority = args.first || Delayed::Worker.default_priority 20: run_at = args[1] 21: self.create(:payload_object => object, :priority => priority.to_i, :run_at => run_at) 22: end
# File lib/delayed/backend/base.rb, line 24 24: def reserve(worker, max_run_time = Worker.max_run_time) 25: # We get up to 5 jobs from the db. In case we cannot get exclusive access to a job we try the next. 26: # this leads to a more even distribution of jobs across the worker processes 27: find_available(worker.name, 5, max_run_time).detect do |job| 28: job.lock_exclusively!(max_run_time, worker.name) 29: end 30: end