Module: ResqueUnit::Scheduler
- Defined in:
- lib/resque_unit/scheduler.rb
Overview
ResqueUnit::Scheduler is a group of functions mocking the behavior of resque-scheduler. It is included into Resque when ‘resque_unit_scheduler’ is required.
Instance Method Summary collapse
-
#enqueue_at(timestamp, klass, *args) ⇒ Object
takes a timestamp which will be used to schedule the job for queueing.
-
#enqueue_in(number_of_seconds_from_now, klass, *args) ⇒ Object
Identical to enqueue_at but takes number_of_seconds_from_now instead of a timestamp.
- #enqueue_with_timestamp(timestamp, klass, *args) ⇒ Object
- #remove_delayed(klass, *args) ⇒ Object
- #remove_delayed_job_from_timestamp(timestamp, klass, *args) ⇒ Object
Instance Method Details
#enqueue_at(timestamp, klass, *args) ⇒ Object
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.
11 12 13 |
# File 'lib/resque_unit/scheduler.rb', line 11 def enqueue_at(, klass, *args) (, klass, *args) end |
#enqueue_in(number_of_seconds_from_now, klass, *args) ⇒ Object
Identical to enqueue_at but takes number_of_seconds_from_now instead of a timestamp.
17 18 19 |
# 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) ⇒ Object
21 22 23 |
# File 'lib/resque_unit/scheduler.rb', line 21 def (, klass, *args) enqueue_unit(queue_for(klass), {"class" => klass.name, "args" => args, "timestamp" => }) end |
#remove_delayed(klass, *args) ⇒ Object
25 26 27 28 29 30 |
# 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) ⇒ Object
32 33 34 35 36 |
# File 'lib/resque_unit/scheduler.rb', line 32 def (, 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(.to_s).to_i && e["args"] == args } end |