Module: SidekiqUniqueJobs::Middleware

Includes:
JSON, Logging::Middleware, OptionsWithFallback
Included in:
Client, Server
Defined in:
lib/sidekiq_unique_jobs/middleware.rb,
lib/sidekiq_unique_jobs/middleware/client.rb,
lib/sidekiq_unique_jobs/middleware/server.rb

Overview

Provides the sidekiq middleware that makes the gem work

Author:

Defined Under Namespace

Classes: Client, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JSON

dump_json, load_json, safe_load_json

Methods included from OptionsWithFallback

included, #lock_class, #lock_instance, #lock_type, #locks, #options, #unique_disabled?, #unique_enabled?

Methods included from Logging::Middleware

included, #logging_context

Methods included from Logging

#build_message, included, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context, #with_configured_loggers_context, #with_logging_context

Instance Attribute Details

#itemHash (readonly)

The sidekiq job hash

Returns:

  • (Hash)

    the Sidekiq job hash



16
17
18
# File 'lib/sidekiq_unique_jobs/middleware.rb', line 16

def item
  @item
end

Instance Method Details

#call(worker_class, item, queue, redis_pool = nil) {|if| ... } ⇒ yield<super>

This method runs before (prepended) the actual middleware implementation.

This is done to reduce duplication

Parameters:

  • worker_class (Sidekiq::Worker)
  • item (Hash)

    a sidekiq job hash

  • queue (String)

    name of the queue

  • redis_pool (ConnectionPool) (defaults to: nil)

    only used for compatility reasons

Yield Parameters:

  • if (<type>)

    <description>

Yield Returns:

  • (<type>)

    <describe what yield should return>

Returns:

  • (yield<super>)

    <description>



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sidekiq_unique_jobs/middleware.rb', line 31

def call(worker_class, item, queue, redis_pool = nil)
  @item       = item
  @queue      = queue
  @redis_pool = redis_pool
  self.job_class = item[CLASS]
  return yield if unique_disabled?

  SidekiqUniqueJobs::Job.prepare(item) unless item[LOCK_DIGEST]

  with_logging_context do
    super
  end
end