Module: Resque::Plugins::Groups::TrackedJob
- Defined in:
- lib/resque_groups/tracked_job.rb
Instance Method Summary collapse
-
#after_enqueue_count_job(*args) ⇒ Object
resque hook, triggered immediately after a job with *args has been enqueued.
-
#after_perform_update_completed(*args) ⇒ Object
resque hook, triggered immediately after a job has been performed.
-
#atomic_op_on_complete ⇒ Object
The MongoDB atomic operation stored in this variable will be executed on the group when and if the job is complete.
- #atomic_op_on_complete=(op) ⇒ Object
-
#is_delayed(*args) ⇒ Object
Determines if this was a delayed job or not, based on the :delayed => true arg.
-
#on_failure_update_failed(exception, *args) ⇒ Object
resque hook, triggered if a job raises any exception.
Instance Method Details
#after_enqueue_count_job(*args) ⇒ Object
resque hook, triggered immediately after a job with *args has been enqueued
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/resque_groups/tracked_job.rb', line 20 def after_enqueue_count_job(*args) gid = Resque.parse_gid(*args) raise "The 'group_id' parameter is missing!" if gid.nil? # If this was a scheduled/delayed job, decrement the 'delayed' counter Resque.delete_delayed_job(gid) if !is_delayed(args).nil? # Update the total count for the group in which the enqueued job belongs Resque.upsert_group(gid) end |
#after_perform_update_completed(*args) ⇒ Object
resque hook, triggered immediately after a job has been performed
32 33 34 35 |
# File 'lib/resque_groups/tracked_job.rb', line 32 def after_perform_update_completed(*args) gid = Resque.parse_gid(*args) Resque.record_performed_job(gid, atomic_op_on_complete) end |
#atomic_op_on_complete ⇒ Object
The MongoDB atomic operation stored in this variable will be executed on the group when and if the job is complete. See www.mongodb.org/display/DOCS/Updating for a list of all atomic operations. e.g.:
{'$inc' => {'custom.size' => 3}}
{'$set' => {'custom.api_problem' => true}}
It’s highly recommended to use the “custom” field to store your data, even if no check is done by the plugin.
12 13 14 |
# File 'lib/resque_groups/tracked_job.rb', line 12 def atomic_op_on_complete @atomic_op_on_complete end |
#atomic_op_on_complete=(op) ⇒ Object
15 16 17 |
# File 'lib/resque_groups/tracked_job.rb', line 15 def atomic_op_on_complete=(op) @atomic_op_on_complete = op end |
#is_delayed(*args) ⇒ Object
Determines if this was a delayed job or not, based on the :delayed => true arg
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/resque_groups/tracked_job.rb', line 44 def is_delayed(*args) delayed = nil args.flatten.each do |arg| next unless arg.kind_of? Hash sym_arg = arg.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} if !sym_arg[:delayed].nil? delayed = sym_arg[:delayed] break end end delayed end |
#on_failure_update_failed(exception, *args) ⇒ Object
resque hook, triggered if a job raises any exception. uncaught exceptions propagate up to Resque::Failure
38 39 40 41 |
# File 'lib/resque_groups/tracked_job.rb', line 38 def on_failure_update_failed(exception, *args) gid = Resque.parse_gid(*args) Resque.record_failed_job(gid, exception, *args) end |