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

Concurrency and Throttle cannot both be used on a job #9

Open
wants to merge 1 commit into
base: master
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
10 changes: 4 additions & 6 deletions lib/active_job/traffic_control/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ def lock_key(prefix, job, config_attr)
if config_attr[:key].respond_to?(:call)
"traffic_control:#{prefix}:#{config_attr[:key].call(job)}"
else
@static_job_key ||= begin
if config_attr[:key].present?
"traffic_control:#{prefix}:#{config_attr[:key]}"
else
"traffic_control:#{prefix}:#{cleaned_name}"
end
if config_attr[:key].present?
"traffic_control:#{prefix}:#{config_attr[:key]}"
else
"traffic_control:#{prefix}:#{cleaned_name}"
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions test/active_job/traffic_control_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def perform
end
end

class ThrottleConcurrencyTestJob < ActiveJob::Base
throttle threshold: 2, period: 1.second, drop: true
concurrency 1, drop: true

def perform
end
end

def test_that_it_has_a_version_number
refute_nil ::ActiveJob::TrafficControl::VERSION
end
Expand Down Expand Up @@ -196,6 +204,13 @@ def test_everything_at_once
EverythingBaseJob.perform_now
assert_equal 1, $count
end

def test_throttle_concurrency_different_keys
job = ThrottleConcurrencyTestJob.new
throttle = ThrottleConcurrencyTestJob.throttling_lock_key(job)
concurrency = ThrottleConcurrencyTestJob.concurrency_lock_key(job)
refute_equal throttle, concurrency
end
end

class MemcachedTrafficControlTest < Minitest::Test
Expand Down