Sha256: c8e00d429b0e51e9783b1bfa7e5f211975da51190010b69c868e70923a511c12

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# Usage:
#
# class MyJob
#   def self.perform(arg1, arg2)
#   end
#   include Resque::Plugins::UniqueByArity.new(
#     arity_for_uniqueness: 1,
#     arity_validation: :warning, # or nil, false, or :error
#     unique_at_runtime: true,
#     unique_in_queue: true
#   )
# end
#
# NOTE: DO NOT include this module directly.
#       Use the Resque::Plugins::UniqueByArity approach as above.
#       This module is ultimately extended into the job class.
module Resque
  module UniqueByArity
    module UniqueJob
      def uniq_log(message, config_proxy = nil)
        config_proxy ||= uniq_config
        config_proxy.logger&.send(config_proxy.log_level, message) if config_proxy.logger
      end

      def uniq_debug(message, config_proxy = nil)
        config_proxy ||= uniq_config
        config_proxy.logger&.debug("#{Resque::UniqueByArity::PLUGIN_TAG}#{message}") if config_proxy.debug_mode
      end

      # For per-class config with a block
      def uniqueness_configure
        @uniqueness_configuration ||= Configuration.new
        yield(@uniqueness_configuration)
      end

      #### CONFIG ####
      class << self
        attr_accessor :uniqueness_configuration
      end
      self.uniqueness_configuration = Configuration.new # setup defaults

      def uniqueness_config_reset(config = Configuration.new)
        @uniqueness_configuration = config
      end

      def uniq_config
        @uniqueness_configuration
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resque-unique_by_arity-3.0.2 lib/resque/unique_by_arity/unique_job.rb