Module: Delayed::Backend::Base::ClassMethods

Defined in:
lib/delayed/backend/base.rb

Instance Method Summary collapse

Instance Method Details

#after_forkObject

Hook method that is called after a new worker is forked



39
# File 'lib/delayed/backend/base.rb', line 39

def after_fork; end

#before_forkObject

Hook method that is called before a new worker is forked



36
# File 'lib/delayed/backend/base.rb', line 36

def before_fork; end

#enqueue(*args) ⇒ Object

Add a job to the queue



10
11
12
13
# File 'lib/delayed/backend/base.rb', line 10

def enqueue(*args)
  job_options = Delayed::Backend::JobPreparer.new(*args).prepare
  enqueue_job(job_options)
end

#enqueue_job(options) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/delayed/backend/base.rb', line 15

def enqueue_job(options)
  new(options).tap do |job|
    Delayed::Worker.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



33
# File 'lib/delayed/backend/base.rb', line 33

def recover_from(_error); end

#reserve(worker, max_run_time = Worker.max_run_time) ⇒ Object



24
25
26
27
28
29
30
# 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
  find_available(worker.name, worker.read_ahead, max_run_time).detect do |job|
    job.lock_exclusively!(max_run_time, worker.name)
  end
end

#work_off(num = 100) ⇒ Object



41
42
43
44
# File 'lib/delayed/backend/base.rb', line 41

def work_off(num = 100)
  warn '[DEPRECATION] `Delayed::Job.work_off` is deprecated. Use `Delayed::Worker.new.work_off instead.'
  Delayed::Worker.new.work_off(num)
end