Module: Delayed::Backend::Base::ClassMethods
- Defined in:
- lib/delayed/backend/base.rb
Instance Method Summary collapse
-
#enqueue(*args) ⇒ Object
Add a job to the queue.
- #enqueue_job(options) ⇒ Object
-
#recover_from(_error) ⇒ Object
Allow the backend to attempt recovery from reserve errors.
- #reserve(worker, max_run_time = Worker.max_run_time) ⇒ Object
- #work_off(num = 100) ⇒ Object
Instance Method Details
#enqueue(*args) ⇒ Object
Add a job to the queue
10 11 12 13 |
# File 'lib/delayed/backend/base.rb', line 10 def enqueue(*args) = Delayed::Backend::JobPreparer.new(*args).prepare enqueue_job() end |
#enqueue_job(options) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/delayed/backend/base.rb', line 15 def enqueue_job() new().tap do |job| Delayed.lifecycle.run_callbacks(:enqueue, job) do job.hook(:enqueue) Delayed::Worker.delay_job?(job) ? job.save : job.invoke_job end end end |
#recover_from(_error) ⇒ Object
Allow the backend to attempt recovery from reserve errors
38 |
# File 'lib/delayed/backend/base.rb', line 38 def recover_from(_error); end |
#reserve(worker, max_run_time = Worker.max_run_time) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/delayed/backend/base.rb', line 24 def reserve(worker, max_run_time = Worker.max_run_time) # We get up to 5 jobs from the db. In case we cannot get exclusive access to a job we try the next. # this leads to a more even distribution of jobs across the worker processes claims = 0 find_available(worker.name, worker.read_ahead, max_run_time).select do |job| next if claims >= worker.max_claims job.lock_exclusively!(max_run_time, worker.name).tap do |result| claims += 1 if result end end end |