Sha256: 495c7568f0e56a7426dc2446ecc21f205f913839b1d7ac9dd99c45ef98b18416
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module Sidekiq module JobSignal class ServerMiddleware include ::Sidekiq::ServerMiddleware def initialize(options = {}) @by_jid = options.fetch(:by_jid, true) @by_class = options.fetch(:by_class, false) end def call(job, job_payload, _queue) signalled = ::Sidekiq::JobSignal.quitting?(**quit_options(job)) logger.debug "#{self.class}.call: signalled=#{signalled}" noop_job(job) if signalled yield ensure logger.debug "#{self.class}.call: ensure signalled=#{signalled}" ::Sidekiq::JobSignal.handlers.each { |handler| handler.call(job) } if signalled end private attr_reader :by_jid, :by_class def quit_options(job) {}.tap do |options| options[:job_class] = job.class.name if by_class options[:jid] = job.jid if by_jid end end def noop_job(job) def job.perform(*args) logger.info "Turned #{jid}:#{self.class} into a no-op: #{args.inspect}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-job-signal-0.1.2 | lib/sidekiq/job_signal/server_middleware.rb |