Module: Proby::ResquePlugin
- Defined in:
- lib/proby/resque_plugin.rb
Overview
Automatically notifies Proby when this job starts and finishes.
class SomeJob
extend Proby::ResquePlugin
self.perform
do_stuff
end
end
The Proby Task ID can be set in one of two ways. The most common way is to put the ID in an ENV variable that is set in your crontab. This ID will be transparently passed to the Resque job via Redis.
0 0 * * * PROBY_TASK_ID=abc123 ./queue_some_job
Alternatively, if you’re not using cron and therefore don’t want that support, you can just set the @proby_id ivar in the class, like so.
class SomeJob
extend Proby::ResquePlugin
@proby_id = 'abc123'
self.perform
do_stuff
end
end
Setting the @proby_id variable will take precendence over the ENV variable.
Instance Method Summary collapse
- #around_perform_proby(*args) ⇒ Object
- #before_enqueue_proby(*args) ⇒ Object
- #proby_id(*args) ⇒ Object
- #proby_id_bucket(*args) ⇒ Object
Instance Method Details
#around_perform_proby(*args) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/proby/resque_plugin.rb', line 49 def around_perform_proby(*args) _proby_id = proby_id(*args) Proby.monitor(_proby_id) do yield end end |
#before_enqueue_proby(*args) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/proby/resque_plugin.rb', line 37 def before_enqueue_proby(*args) return true if @proby_id env_proby_id = ENV['PROBY_TASK_ID'] Resque.redis.setex(proby_id_bucket(*args), 24.hours, env_proby_id) return true end |
#proby_id(*args) ⇒ Object
45 46 47 |
# File 'lib/proby/resque_plugin.rb', line 45 def proby_id(*args) @proby_id || Resque.redis.get(proby_id_bucket(*args)) end |
#proby_id_bucket(*args) ⇒ Object
33 34 35 |
# File 'lib/proby/resque_plugin.rb', line 33 def proby_id_bucket(*args) "proby_id:#{name}-#{args.to_s}" end |