Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid race-condition when scheduling throttled jobs #208

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ appraise "sidekiq-7.0.x" do

# Sidekiq Pro license must be set in global bundler config
# or in BUNDLE_GEMS__CONTRIBSYS__COM env variable
install_if "-> { Bundler.settings['gems.contribsys.com']&.include?(':') }" do
if Bundler.settings["gems.contribsys.com"]&.include?(":")
source "https://gems.contribsys.com/" do
gem "sidekiq-pro", "~> 7.0.0"
end
Expand All @@ -20,7 +20,7 @@ appraise "sidekiq-7.1.x" do

# Sidekiq Pro license must be set in global bundler config
# or in BUNDLE_GEMS__CONTRIBSYS__COM env variable
install_if "-> { Bundler.settings['gems.contribsys.com']&.include?(':') }" do
if Bundler.settings["gems.contribsys.com"]&.include?(":")
source "https://gems.contribsys.com/" do
gem "sidekiq-pro", "~> 7.1.0"
end
Expand All @@ -34,7 +34,7 @@ appraise "sidekiq-7.2.x" do

# Sidekiq Pro license must be set in global bundler config
# or in BUNDLE_GEMS__CONTRIBSYS__COM env variable
install_if "-> { Bundler.settings['gems.contribsys.com']&.include?(':') }" do
if Bundler.settings["gems.contribsys.com"]&.include?(":")
source "https://gems.contribsys.com/" do
gem "sidekiq-pro", "~> 7.2.0"
end
Expand Down
2 changes: 2 additions & 0 deletions lib/sidekiq/throttled/strategy/concurrency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def retry_in(_jid, *job_args)
return 0.0 if !job_limit || count(*job_args) < job_limit

oldest_jid_with_score = Sidekiq.redis { |redis| redis.zrange(key(job_args), 0, 0, withscores: true) }.first
return 0.0 unless oldest_jid_with_score

expiry_time = oldest_jid_with_score.last.to_f
expiry_time - Time.now.to_f
end
Expand Down