lib/sidekiq/throttled/config.rb in sidekiq-throttled-1.4.0 vs lib/sidekiq/throttled/config.rb in sidekiq-throttled-1.5.0

- old
+ new

@@ -17,13 +17,22 @@ # {#cooldown_period}. # # @return [Integer] attr_reader :cooldown_threshold + # Specifies how we should return throttled jobs to the queue so they can be executed later. + # Expects a hash with keys that may include :with and :to + # For :with, options are `:enqueue` (put them on the end of the queue) and `:schedule` (schedule for later). + # For :to, the name of a sidekiq queue should be specified. If none is specified, jobs will by default be + # requeued to the same queue they were originally enqueued in. + # Default: {with: `:enqueue`} + # + # @return [Hash] + attr_reader :default_requeue_options + def initialize - @cooldown_period = 2.0 - @cooldown_threshold = 1 + reset! end # @!attribute [w] cooldown_period def cooldown_period=(value) raise TypeError, "unexpected type #{value.class}" unless value.nil? || value.is_a?(Float) @@ -36,9 +45,22 @@ def cooldown_threshold=(value) raise TypeError, "unexpected type #{value.class}" unless value.is_a?(Integer) raise ArgumentError, "threshold must be positive" unless value.positive? @cooldown_threshold = value + end + + # @!attribute [w] default_requeue_options + def default_requeue_options=(options) + requeue_with = options.delete(:with).intern || :enqueue + + @default_requeue_options = options.merge({ with: requeue_with }) + end + + def reset! + @cooldown_period = 1.0 + @cooldown_threshold = 100 + @default_requeue_options = { with: :enqueue } end end end end