lib/sidekiq/throttled/strategy/concurrency.rb in sidekiq-throttled-0.8.1 vs lib/sidekiq/throttled/strategy/concurrency.rb in sidekiq-throttled-0.8.2

- old
+ new

@@ -1,9 +1,10 @@ # frozen_string_literal: true +require "redis/prescription" + require "sidekiq/throttled/strategy/base" -require "sidekiq/throttled/strategy/script" module Sidekiq module Throttled class Strategy # Concurrency throttling strategy @@ -17,11 +18,11 @@ # return 1 # else # PUSH(@key, @jid) # return 0 # end - SCRIPT = Script.read "#{__dir__}/concurrency.lua" + SCRIPT = Redis::Prescription.read "#{__dir__}/concurrency.lua" private_constant :SCRIPT # @param [#to_s] strategy_key # @param [#to_i, #call] limit Amount of allowed concurrent jobs # per processors running for given key. @@ -41,13 +42,15 @@ # @return [Boolean] whenever job is throttled or not def throttled?(jid, *job_args) return false unless (job_limit = limit(job_args)) - keys = [key(job_args)] - args = [jid.to_s, job_limit, @ttl, Time.now.to_f] + kwargs = { + :keys => [key(job_args)], + :argv => [jid.to_s, job_limit, @ttl, Time.now.to_f] + } - 1 == SCRIPT.eval(keys, args) + Sidekiq.redis { |redis| 1 == SCRIPT.eval(redis, kwargs) } end # @return [Integer] Current count of jobs def count(*job_args) Sidekiq.redis { |conn| conn.zcard(key(job_args)) }.to_i