Class: JobsDashboard::ClientMiddleware

Inherits:
Object
  • Object
show all
Includes:
Storage
Defined in:
lib/jobs_dashboard/client_middleware.rb

Overview

Should be in the client middleware chain

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ClientMiddleware

Parameterized initialization, use it when adding middleware to client chain chain.add JobsDashboard::ClientMiddleware

Parameters:

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

    middleware initialization options

Options Hash (opts):

  • :expiration (Fixnum)

    ttl for complete jobs



13
14
15
# File 'lib/jobs_dashboard/client_middleware.rb', line 13

def initialize(opts = {})
  @expiration = opts[:expiration]
end

Instance Method Details

#call(worker, 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 JobsDashboard::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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jobs_dashboard/client_middleware.rb', line 22

def call(worker, msg, queue, redis_pool=nil)
  unless get_jobs_dashboard_options(msg)[:skip]
    store_for_id(msg['jid'], {
      item_type: msg['class'],
      retry: msg['retry'],
      queue: msg['queue'],
      args: msg['args'],
      status: 'queued'
    })
  end

  yield

end