module ResqueUnit::Scheduler

ResqueUnit::Scheduler is a group of functions mocking the behavior of resque-scheduler. It is included into Resque when ‘resque_unit_scheduler’ is required.

Public Instance Methods

enqueue_at(timestamp, klass, *args) click to toggle source

takes a timestamp which will be used to schedule the job for queueing. Until timestamp is in the past, the job will sit in the schedule list.

# File lib/resque_unit/scheduler.rb, line 11
def enqueue_at(timestamp, klass, *args)
  enqueue_with_timestamp(timestamp, klass, *args)
end
enqueue_in(number_of_seconds_from_now, klass, *args) click to toggle source

Identical to enqueue_at but takes number_of_seconds_from_now instead of a timestamp.

# File lib/resque_unit/scheduler.rb, line 17
def enqueue_in(number_of_seconds_from_now, klass, *args)
  enqueue_at(Time.now + number_of_seconds_from_now, klass, *args)
end
enqueue_with_timestamp(timestamp, klass, *args) click to toggle source
# File lib/resque_unit/scheduler.rb, line 21
def enqueue_with_timestamp(timestamp, klass, *args)
  enqueue_unit(queue_for(klass), {"class" => klass.name, "args" => args, "timestamp" => timestamp})
end
remove_delayed(klass, *args) click to toggle source
# File lib/resque_unit/scheduler.rb, line 25
def remove_delayed(klass, *args)
  # points to real queue
  encoded_job_payloads = Resque.queue(queue_for(klass))
  args ||= []
  encoded_job_payloads.delete_if { |e| e = Resque.decode(e); e["class"] == klass.to_s && e["args"] == args }
end
remove_delayed_job_from_timestamp(timestamp, klass, *args) click to toggle source
# File lib/resque_unit/scheduler.rb, line 32
def remove_delayed_job_from_timestamp(timestamp, klass, *args)
  encoded_job_payloads = Resque.queue(queue_for(klass))
  args ||= []
  encoded_job_payloads.delete_if { |e| e = Resque.decode(e); e["class"] == klass.to_s && Time.parse(e["timestamp"]).to_i == Time.parse(timestamp.to_s).to_i && e["args"] == args }
end