Class: Sidekiq::Hierarchy::Client::Middleware
- Inherits:
-
Object
- Object
- Sidekiq::Hierarchy::Client::Middleware
- Defined in:
- lib/sidekiq/hierarchy/client/middleware.rb
Instance Method Summary collapse
-
#call(worker_class, msg, queue, redis_pool = nil) ⇒ Object
Wraps around the method used to push a job to Redis.
-
#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/client/middleware.rb', line 5 def initialize(={}) end |
Instance Method Details
#call(worker_class, msg, queue, redis_pool = nil) ⇒ Object
Wraps around the method used to push a job to Redis. Takes params:
worker_class - the class of the worker, as an object
msg - the hash of job info, something like {'class' => 'HardWorker', 'args' => [1, 2, 'foo'], 'retry' => true}
queue - the named queue to use
redis_pool - a redis-like connection/conn-pool
Must propagate return value upwards. May return false/nil to stop the job from going to redis.
15 16 17 18 19 |
# File 'lib/sidekiq/hierarchy/client/middleware.rb', line 15 def call(worker_class, msg, queue, redis_pool=nil) msg['workflow'] = Sidekiq::Hierarchy.current_workflow.jid if Sidekiq::Hierarchy.current_workflow # if block returns nil/false, job was cancelled before queueing by middleware yield.tap { |job| Sidekiq::Hierarchy.record_job_enqueued(job) if job } end |