Class: Ruote::Resque::Participant
- Inherits:
-
Object
- Object
- Ruote::Resque::Participant
- Includes:
- LocalParticipant
- Defined in:
- lib/ruote/resque/participant.rb
Overview
A module to be included in your Resque jobs to be able to register them as participants.
Note that the participant should have a queue, either via the @queue
variable
when the class is accessible to Ruote, or via the :queue
option on registration
A resque participant implementation.
Instance Method Summary collapse
-
#do_not_thread ⇒ true
Returns true because enqueing a job in Resque is sufficiently fast to happen in the main thread.
-
#encode_workitem(workitem) ⇒ Hash
Returns a representation of a workitem that is suitable for use in Resque.
-
#initialize(opts = {}) ⇒ Participant
constructor
Called with the options on
engine.register_participant
. -
#on_cancel ⇒ Boolean
Called when Ruote has to cancel an active workitem for this participant.
-
#on_workitem ⇒ void
Called when the participant is handed a workitem.
Constructor Details
#initialize(opts = {}) ⇒ Participant
Called with the options on engine.register_participant
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruote/resque/participant.rb', line 36 def initialize(opts = {}) @job_klass = opts.delete('class') @job_queue = opts.delete('queue') @should_forget = opts.delete('forget') || false # Called here to raise eventual exceptions on initialization ::Resque.validate(@job_klass, @job_queue) end |
Instance Method Details
#do_not_thread ⇒ true
Returns true because enqueing a job in Resque is sufficiently fast to happen in the main thread.
83 84 85 |
# File 'lib/ruote/resque/participant.rb', line 83 def do_not_thread true end |
#encode_workitem(workitem) ⇒ Hash
Returns a representation of a workitem that is suitable for use in Resque.
75 76 77 78 79 |
# File 'lib/ruote/resque/participant.rb', line 75 def encode_workitem(workitem) workitem.to_h end |
#on_cancel ⇒ Boolean
Called when Ruote has to cancel an active workitem for this participant. Destroys the job from the Resque queue.
Note that if the job is being processed by the worker or if the job has been processed but the reply has not, this method will do nothing.
65 66 67 68 69 70 |
# File 'lib/ruote/resque/participant.rb', line 65 def on_cancel payload = encode_workitem(applied_workitem) ::Resque::Job.destroy(@job_queue, @job_klass, payload) end |
#on_workitem ⇒ void
This method returns an undefined value.
Called when the participant is handed a workitem. Enqueues the job to Resque
50 51 52 53 54 55 56 57 |
# File 'lib/ruote/resque/participant.rb', line 50 def on_workitem payload = encode_workitem(workitem) ::Resque::Job.create(@job_queue, @job_klass, payload) reply if @should_forget end |