lib/sidekiq/throttled/patches/basic_fetch.rb in sidekiq-throttled-1.2.0 vs lib/sidekiq/throttled/patches/basic_fetch.rb in sidekiq-throttled-1.3.0
- old
+ new
@@ -1,29 +1,18 @@
# frozen_string_literal: true
require "sidekiq"
require "sidekiq/fetch"
+require_relative "./throttled_retriever"
+
module Sidekiq
module Throttled
module Patches
module BasicFetch
- # Retrieves job from redis.
- #
- # @return [Sidekiq::Throttled::UnitOfWork, nil]
- def retrieve_work
- work = super
-
- if work && Throttled.throttled?(work.job)
- Throttled.cooldown&.notify_throttled(work.queue)
- requeue_throttled(work)
- return nil
- end
-
- Throttled.cooldown&.notify_admitted(work.queue) if work
-
- work
+ def self.prepended(base)
+ base.prepend(ThrottledRetriever)
end
private
# Pushes job back to the head of the queue, so that job won't be tried
@@ -41,10 +30,13 @@
#
# @note It may return an empty array.
# @param [Array<String>] queues
# @return [Array<String>]
def queues_cmd
- super - (Throttled.cooldown&.queues || [])
+ throttled_queues = Throttled.cooldown&.queues
+ return super if throttled_queues.nil? || throttled_queues.empty?
+
+ super - throttled_queues
end
end
end
end
end