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



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

def after_fork
end

#before_forkObject

Hook method that is called before a new worker is forked



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

def before_fork
end

#enqueue(*args) ⇒ Object

Add a job to the queue



10
11
12
13
14
15
16
17
18
19
# File 'lib/delayed/backend/base.rb', line 10

def enqueue(*args)
  object = args.shift
  unless object.respond_to?(:perform)
    raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
  end
    
  priority = args.first || Delayed::Worker.default_priority
  run_at   = args[1]
  self.create(:payload_object => object, :priority => priority.to_i, :run_at => run_at)
end

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



21
22
23
24
25
26
27
# File 'lib/delayed/backend/base.rb', line 21

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, 5, max_run_time, worker.queues).detect do |job|
    job.lock_exclusively!(max_run_time, worker.name)
  end
end

#work_off(num = 100) ⇒ Object



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

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