Module: Sidekiq::Status

Extended by:
Storage
Defined in:
lib/sidekiq-status/web.rb,
lib/sidekiq-status/version.rb,
lib/sidekiq-status/testing/inline.rb,
lib/sidekiq-status/client_middleware.rb,
lib/sidekiq-status/server_middleware.rb,
lib/sidekiq-status.rb

Overview

Defined Under Namespace

Modules: Storage, Web, Worker Classes: ClientMiddleware, ServerMiddleware

Constant Summary collapse

VERSION =
'1.1.4'
DEFAULT_EXPIRY =
60 * 30
STATUS =
[ :queued, :working, :retrying, :complete, :stopped, :failed, :interrupted ].freeze

Constants included from Storage

Storage::BATCH_LIMIT, Storage::RESERVED_FIELDS

Class Method Summary collapse

Class Method Details

.at(job_id) ⇒ Object

Methods for retrieving job completion


52
53
54
# File 'lib/sidekiq-status.rb', line 52

def at(job_id)
  get(job_id, :at).to_i
end

.cancel(job_id, job_unix_time = nil) ⇒ Object Also known as: unschedule


35
36
37
# File 'lib/sidekiq-status.rb', line 35

def cancel(job_id, job_unix_time = nil)
  delete_and_unschedule(job_id, job_unix_time)
end

.configure_client_middleware(sidekiq_config, client_middleware_options = {}) ⇒ Object

Helper method to easily configure sidekiq-status client middleware whatever the Sidekiq version is.

Parameters:

  • sidekiq_config (Sidekiq)

    the Sidekiq config

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

    client middleware initialization options

Options Hash (client_middleware_options):

  • :expiration (Fixnum)

    ttl for complete jobs


61
62
63
64
65
# File 'lib/sidekiq-status/client_middleware.rb', line 61

def self.configure_client_middleware(sidekiq_config, client_middleware_options = {})
  sidekiq_config.client_middleware do |chain|
    chain.add Sidekiq::Status::ClientMiddleware, client_middleware_options
  end
end

.configure_server_middleware(sidekiq_config, server_middleware_options = {}) ⇒ Object

Helper method to easily configure sidekiq-status server middleware whatever the Sidekiq version is.

Parameters:

  • sidekiq_config (Sidekiq)

    the Sidekiq config

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

    server middleware initialization options

Options Hash (server_middleware_options):

  • :expiration (Fixnum)

    ttl for complete jobs


92
93
94
95
96
97
98
99
100
101
102
# File 'lib/sidekiq-status/server_middleware.rb', line 92

def self.configure_server_middleware(sidekiq_config, server_middleware_options = {})
  sidekiq_config.server_middleware do |chain|
    if Sidekiq.major_version < 5
      chain.insert_after Sidekiq::Middleware::Server::Logging,
        Sidekiq::Status::ServerMiddleware, server_middleware_options
    else
      chain.add Sidekiq::Status::ServerMiddleware, server_middleware_options
    end
  end

end

.delete(job_id) ⇒ Object


39
40
41
# File 'lib/sidekiq-status.rb', line 39

def delete(job_id)
  delete_status(job_id)
end

.get(job_id, field) ⇒ String

Job status by id

Parameters:

  • id (String)

    job id returned by async_perform

Returns:

  • (String)

    job status, possible values are in STATUS


19
20
21
# File 'lib/sidekiq-status.rb', line 19

def get(job_id, field)
  read_field_for_id(job_id, field)
end

.get_all(job_id) ⇒ Hash

Get all status fields for a job

Returns:

  • (Hash)

    hash of all fields stored for the job


26
27
28
# File 'lib/sidekiq-status.rb', line 26

def get_all(job_id)
  read_hash_for_id(job_id)
end

.message(job_id) ⇒ Object


64
65
66
# File 'lib/sidekiq-status.rb', line 64

def message(job_id)
  get(job_id, :message)
end

.pct_complete(job_id) ⇒ Object


60
61
62
# File 'lib/sidekiq-status.rb', line 60

def pct_complete(job_id)
  get(job_id, :pct_complete).to_i
end

.status(job_id) ⇒ Object


4
5
6
# File 'lib/sidekiq-status/testing/inline.rb', line 4

def status(jid)
  :complete
end

.total(job_id) ⇒ Object


56
57
58
# File 'lib/sidekiq-status.rb', line 56

def total(job_id)
  get(job_id, :total).to_i
end