Class: Sidekiq::Status::ClientMiddleware

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(opts = {}) ⇒ ClientMiddleware

Parameterized initialization, use it when adding middleware to client chain chain.add Sidekiq::Status::ClientMiddleware, :expiration => 60 * 5

Parameters:

  • opts (Hash) (defaults to: {})

    middleware initialization options

Options Hash (opts):

  • :expiration (Fixnum)

    ttl for complete jobs


10
11
12
# File 'lib/sidekiq-status/client_middleware.rb', line 10

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

Parameters:

  • worker_class (Class)

    if includes Sidekiq::Status::Worker, the job gets processed with the plugin

  • msg (Array)

    job arguments

  • queue (String)

    the queue's name

  • redis_pool (ConnectionPool) (defaults to: nil)

    optional redis connection pool


19
20
21
22
23
24
25
26
27
28
# File 'lib/sidekiq-status/client_middleware.rb', line 19

def call(worker_class, msg, queue, redis_pool=nil)
   = { 
    jid: msg['jid'],
    status: :queued,
    worker: worker_class, 
    args: msg['args'].to_a.empty? ? nil : msg['args']
  }
  store_for_id msg['jid'], , @expiration, redis_pool
  yield
end