Sha256: fb22b936cef97f51b0ee1f573d54421dccbfb0b0fa8b405bbc1a236675f04d98

Contents?: true

Size: 976 Bytes

Versions: 1

Compression:

Stored size: 976 Bytes

Contents

module Sidekiq
  module Hierarchy
    module Client
      class Middleware
        def initialize(options={})
        end

        # Wraps around the method used to push a job to Redis. Takes params:
        #   worker_class - the class of the worker, as an object
        #   msg - the hash of job info, something like {'class' => 'HardWorker', 'args' => [1, 2, 'foo'], 'retry' => true}
        #   queue - the named queue to use
        #   redis_pool - a redis-like connection/conn-pool
        # Must propagate return value upwards.
        # May return false/nil to stop the job from going to redis.
        def call(worker_class, msg, queue, redis_pool)
          msg['workflow'] = Sidekiq::Hierarchy.current_workflow.jid if Sidekiq::Hierarchy.current_workflow
          # if block returns nil/false, job was cancelled before queueing by middleware
          yield.tap { |job| Sidekiq::Hierarchy.record_job_enqueued(job) if job }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-hierarchy-0.1.1 lib/sidekiq/hierarchy/client/middleware.rb