Class: Sidekiq::Hierarchy::Server::Middleware
- Inherits:
-
Object
- Object
- Sidekiq::Hierarchy::Server::Middleware
- Defined in:
- lib/sidekiq/hierarchy/server/middleware.rb
Instance Method Summary collapse
-
#call(worker, msg, queue) ⇒ Object
Wraps around the actual execution of a job.
-
#initialize(options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(options = {}) ⇒ Middleware
Returns a new instance of Middleware.
5 6 |
# File 'lib/sidekiq/hierarchy/server/middleware.rb', line 5 def initialize(={}) end |
Instance Method Details
#call(worker, msg, queue) ⇒ Object
Wraps around the actual execution of a job. Takes params:
worker - the instance of the worker to be used for execution
msg - the hash of job info, something like {'class' => 'HardWorker', 'args' => [1, 2, 'foo'], 'retry' => true}
queue - the named queue to use
Must propagate return value upwards. Since jobs raise errors for signalling, those must be propagated as well.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sidekiq/hierarchy/server/middleware.rb', line 14 def call(worker, msg, queue) if msg['workflow'] == true # root job -- start of a new workflow Sidekiq::Hierarchy.current_workflow = Workflow.find_by_jid(worker.jid) Sidekiq::Hierarchy.current_job = Sidekiq::Hierarchy.current_workflow.root elsif msg['workflow'].is_a?(String) # child job -- inherit parent's workflow Sidekiq::Hierarchy.current_workflow = Workflow.find_by_jid(msg['workflow']) Sidekiq::Hierarchy.current_job = Job.find(worker.jid) end Sidekiq::Hierarchy.record_job_running ret = yield Sidekiq::Hierarchy.record_job_complete ret rescue Exception => e if exception_caused_by_shutdown?(e) || retries_remaining?(msg) # job will be pushed back onto queue during hard_shutdown or if retries are permitted Sidekiq::Hierarchy.record_job_requeued else Sidekiq::Hierarchy.record_job_failed end raise end |