Sha256: dfb2fe77447a01da82f13e1e8d972c7a9b8f7754b018e4408b18807ac31fc2d8

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

require 'sidekiq/api'

module Sidekiq
  class Job
    module UniqueExtension
      def self.included(base)
        base.class_eval do
          alias_method :delete_orig, :delete
          alias_method :delete, :delete_ext
        end
      end

      def delete_ext
        unlock(payload_hash(item))
        delete_orig
      end

      protected

      def payload_hash(item)
        SidekiqUniqueJobs::PayloadHelper.get_payload(item['class'], item['queue'], item['args'])
      end

      def unlock(payload_hash)
        Sidekiq.redis { |conn| conn.del(payload_hash) }
      end
    end
    include UniqueExtension
  end

  class Queue
    module UniqueExtension
      def self.included(base)
        base.class_eval do
          alias_method :clear_orig, :clear
          alias_method :clear, :clear_ext
        end
      end

      def clear_ext
        each(&:delete)
        clear_orig
      end
    end

    include UniqueExtension
  end

  class JobSet
    module UniqueExtension
      def self.included(base)
        base.class_eval do
          if base.method_defined?(:clear)
            alias_method :clear_orig, :clear
            alias_method :clear, :clear_ext
          end
        end
      end

      def clear_ext
        each(&:delete_ext)
        clear_orig
      end
    end

    include UniqueExtension
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-3.0.14 lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb
sidekiq-unique-jobs-3.0.13 lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb
sidekiq-unique-jobs-3.0.12 lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb
sidekiq-unique-jobs-3.0.11 lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb
sidekiq-unique-jobs-3.0.10 lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb
sidekiq-unique-jobs-3.0.9 lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb
sidekiq-unique-jobs-3.0.8 lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb