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

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) after_fork

Hook method that is called after a new worker is forked



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

def after_fork
end

- (Object) before_fork

Hook method that is called before a new worker is forked



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

def before_fork
end

- (Object) enqueue(*args)

Add a job to the queue



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/delayed/backend/base.rb', line 10

def enqueue(*args)
  options = {
    :priority => Delayed::Worker.default_priority
  }.merge!(args.extract_options!)

  options[:payload_object] ||= args.shift

  if args.size > 0
    warn "[DEPRECATION] Passing multiple arguments to `#enqueue` is deprecated. Pass a hash with :priority and :run_at."
    options[:priority] = args.first || options[:priority]
    options[:run_at]   = args[1]
  end

  unless options[:payload_object].respond_to?(:perform)
    raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
  end
  
  if Delayed::Worker.delay_jobs
    self.create(options).tap do |job|
      job.hook(:enqueue)
    end
  else
    options[:payload_object].perform
  end
end

- (Object) reserve(worker, max_run_time = Worker.max_run_time)



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

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

- (Object) work_off(num = 100)



52
53
54
55
# File 'lib/delayed/backend/base.rb', line 52

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