5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/sidekiq/throttled_worker/concurrency.rb', line 5
def limit?(worker_class, jid)
concurrency = worker_class.get_sidekiq_options["concurrency"]
ttl = (worker_class.get_sidekiq_options["concurrency_ttl"] || 900) now = Time.now.to_f
Sidekiq::ThrottledWorker.redis.with do |conn|
conn.zremrangebyscore(concurrency_key(worker_class), "-inf", "(#{now}")
return true if conn.zcard(concurrency_key(worker_class)) >= concurrency && conn.zscore(concurrency_key(worker_class), jid).nil?
conn.zadd(concurrency_key(worker_class), (now + ttl).to_i, jid)
conn.expire(concurrency_key(worker_class), (now + ttl).to_i)
false
end
end
|