Module: Qu::Extensions::Scheduler
- Defined in:
- lib/qu/extensions/scheduler.rb,
lib/qu/extensions/scheduler/redis.rb
Defined Under Namespace
Modules: Redis
Instance Method Summary collapse
-
#delayed_timestamp_peek(timestamp, start, count) ⇒ Object
Returns an array of delayed items for the given timestamp.
-
#enqueue_at(timestamp, klass, *args) ⇒ Object
This method is nearly identical to
enqueue
only it also 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.
-
#reload_schedule! ⇒ Object
reloads the schedule from redis.
-
#schedule ⇒ Object
Returns the schedule hash.
-
#schedule=(schedule_hash) ⇒ Object
Accepts a new schedule configuration of the form:.
Instance Method Details
#delayed_timestamp_peek(timestamp, start, count) ⇒ Object
Returns an array of delayed items for the given timestamp
77 78 79 80 81 82 83 84 |
# File 'lib/qu/extensions/scheduler.rb', line 77 def (, start, count) if 1 == count r = backend.list_range "delayed:#{.to_i}", start, count r.nil? ? [] : [r] else backend.list_range "delayed:#{.to_i}", start, count end end |
#enqueue_at(timestamp, klass, *args) ⇒ Object
This method is nearly identical to enqueue
only it also 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.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/qu/extensions/scheduler.rb', line 57 def enqueue_at(, klass, *args) before_hooks = before_schedule_hooks(klass).collect do |hook| klass.send(hook,*args) end return false if before_hooks.any? { |result| result == false } backend.delayed_push(, Payload.new(:klass => klass, :args => args)) after_schedule_hooks(klass).collect do |hook| klass.send(hook,*args) end 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.
72 73 74 |
# File 'lib/qu/extensions/scheduler.rb', line 72 def enqueue_in(number_of_seconds_from_now, klass, *args) enqueue_at(Time.now + number_of_seconds_from_now, klass, *args) end |
#reload_schedule! ⇒ Object
reloads the schedule from redis
49 50 51 |
# File 'lib/qu/extensions/scheduler.rb', line 49 def reload_schedule! @schedule = backend.get_schedules end |
#schedule ⇒ Object
Returns the schedule hash
44 45 46 |
# File 'lib/qu/extensions/scheduler.rb', line 44 def schedule @schedule ||= {} end |
#schedule=(schedule_hash) ⇒ Object
Accepts a new schedule configuration of the form:
{'some_name' => {"cron" => "5/* * * *",
"class" => "DoSomeWork",
"args" => "work on this string",
"description" => "this thing works it"s butter off"},
...}
‘some_name’ can be anything and is used only to describe and reference the scheduled job
:cron can be any cron scheduling string :job can be any resque job class
:every can be used in lieu of :cron. see rufus-scheduler’s ‘every’ usage for valid syntax. If :cron is present it will take precedence over :every.
:class must be a resque worker class
:args can be any yaml which will be converted to a ruby literal and passed in a params. (optional)
:rails_envs is the list of envs where the job gets loaded. Envs are comma separated (optional)
:description is just that, a description of the job (optional). If params is an array, each element in the array is passed as a separate param, otherwise params is passed in as the only parameter to perform.
34 35 36 37 38 39 40 41 |
# File 'lib/qu/extensions/scheduler.rb', line 34 def schedule=(schedule_hash) if Qu::Scheduler.dynamic schedule_hash.each do |name, job_spec| backend.set_schedule(name, job_spec) end end @schedule = schedule_hash end |