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

Support setting false-y values for cache_client #23

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
4 changes: 3 additions & 1 deletion lib/active_job/traffic_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class << self
attr_accessor :client_klass

def cache_client
@cache_client ||= begin
return @cache_client if defined?(@cache_client)

@cache_client = begin
if defined?(Rails.cache)
Rails.cache
else
Expand Down
4 changes: 4 additions & 0 deletions lib/active_job/traffic_control/disable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ module Disable

class_methods do
def disable!(drop: false)
return false unless cache_client

cache_client.write(disable_key, drop ? SHOULD_DROP : SHOULD_DISABLE)
end

def enable!
return false unless cache_client

cache_client.delete(disable_key)
end

Expand Down
3 changes: 3 additions & 0 deletions test/active_job/traffic_control_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def test_disable
DisableTestJob.enable!
DisableTestJob.perform_now
assert_equal 2, $count

ActiveJob::TrafficControl.cache_client = false
DisableTestJob.perform_now
end

def throttle_helper(klass)
Expand Down