Sha256: de9f9b74db2c0c90c16cc40a7c2eec6fad89e209ddb4771eaa0f6ae7b064563e

Contents?: true

Size: 1.64 KB

Versions: 11

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  module OnConflict
    # Strategy to send jobs to dead queue
    #
    # @author Mikael Henriksson <mikael@mhenrixon.com>
    class Reject < OnConflict::Strategy
      include SidekiqUniqueJobs::Timing

      # Send jobs to dead queue
      def call
        log_info { "Adding dead #{item[CLASS]} job #{item[JID]}" }

        if kill_with_options?
          kill_job_with_options
        else
          kill_job_without_options
        end
      end

      #
      # Sidekiq version compatibility check
      # @api private
      #
      #
      # @return [true] when Sidekiq::Deadset#kill takes more than 1 argument
      # @return [false] when Sidekiq::Deadset#kill does not take multiple arguments
      #
      def kill_with_options?
        Sidekiq::DeadSet.instance_method(:kill).arity > 1
      end

      #
      # Executes the kill instructions without arguments
      # @api private
      #
      # @return [void]
      #
      def kill_job_without_options
        deadset.kill(payload)
      end

      #
      # Executes the kill instructions with arguments
      # @api private
      #
      # @return [void]
      #
      def kill_job_with_options
        deadset.kill(payload, notify_failure: false)
      end

      #
      # An instance of Sidekiq::Deadset
      # @api private
      #
      # @return [Sidekiq::Deadset]>
      #
      def deadset
        @deadset ||= Sidekiq::DeadSet.new
      end

      #
      # The Sidekiq job hash as JSON
      #
      #
      # @return [String] a JSON formatted string
      #
      def payload
        @payload ||= dump_json(item)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.10 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.9 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.8 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.7 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.6 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.5 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.4 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.3 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/on_conflict/reject.rb
sidekiq-unique-jobs-8.0.0 lib/sidekiq_unique_jobs/on_conflict/reject.rb