Delayed::Backend::Base::ClassMethods

Public Instance Methods

after_fork() click to toggle source

Hook method that is called after a new worker is forked

# File lib/delayed/backend/base.rb, line 59
def after_fork
end
before_fork() click to toggle source

Hook method that is called before a new worker is forked

# File lib/delayed/backend/base.rb, line 55
def before_fork
end
enqueue(*args) click to toggle source

Add a job to the queue

# File lib/delayed/backend/base.rb, line 10
def enqueue(*args)
  options = {
    :priority => Delayed::Worker.default_priority,
    :queue => Delayed::Worker.default_queue_name
  }.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.new(options).tap do |job|
      Delayed::Worker.lifecycle.run_callbacks(:enqueue, job) do
        job.hook(:enqueue)
        job.save
      end
    end
  else
    Delayed::Job.new(:payload_object => options[:payload_object]).tap do |job|
      job.invoke_job
    end
  end
end
recover_from(error) click to toggle source

Allow the backend to attempt recovery from reserve errors

# File lib/delayed/backend/base.rb, line 51
def recover_from(error)
end
reserve(worker, max_run_time = Worker.max_run_time) click to toggle source
# File lib/delayed/backend/base.rb, line 42
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) click to toggle source
# File lib/delayed/backend/base.rb, line 62
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.