Class: Sidekiq::Status::ClientMiddleware
- Inherits:
-
Object
- Object
- Sidekiq::Status::ClientMiddleware
- Includes:
- Storage
- Defined in:
- lib/sidekiq-status/client_middleware.rb
Overview
Should be in the client middleware chain
Constant Summary
Constants included from Storage
Storage::BATCH_LIMIT, Storage::RESERVED_FIELDS
Instance Method Summary collapse
-
#call(worker_class, msg, queue, redis_pool = nil) ⇒ Object
Uses msg id and puts :queued status in the job’s Redis hash.
- #display_args(msg, queue) ⇒ Object
-
#initialize(opts = {}) ⇒ ClientMiddleware
constructor
Parameterized initialization, use it when adding middleware to client chain chain.add Sidekiq::Status::ClientMiddleware, :expiration => 60 * 5.
Constructor Details
#initialize(opts = {}) ⇒ ClientMiddleware
Parameterized initialization, use it when adding middleware to client chain chain.add Sidekiq::Status::ClientMiddleware, :expiration => 60 * 5
11 12 13 |
# File 'lib/sidekiq-status/client_middleware.rb', line 11 def initialize(opts = {}) @expiration = opts[:expiration] end |
Instance Method Details
#call(worker_class, msg, queue, redis_pool = nil) ⇒ Object
Uses msg id and puts :queued status in the job’s Redis hash
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sidekiq-status/client_middleware.rb', line 20 def call(worker_class, msg, queue, redis_pool=nil) # Determine the actual job class klass = msg["args"][0]["job_class"] || worker_class rescue worker_class job_class = klass.is_a?(Class) ? klass : Module.const_get(klass) # Store data if the job is a Sidekiq::Status::Worker if job_class.ancestors.include?(Sidekiq::Status::Worker) = { jid: msg['jid'], status: :queued, worker: Sidekiq::Job.new(msg, queue).display_class, args: display_args(msg, queue) } store_for_id msg['jid'], , job_class.new.expiration || @expiration, redis_pool end yield end |
#display_args(msg, queue) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/sidekiq-status/client_middleware.rb', line 41 def display_args(msg, queue) job = Sidekiq::Job.new(msg, queue) return job.display_args.to_a.empty? ? nil : job.display_args.to_json rescue Exception => e # For Sidekiq ~> 2.7 return msg['args'].to_a.empty? ? nil : msg['args'].to_json end |