Module: ActiveJob::TrafficControl
- Defined in:
- lib/active_job/traffic_control.rb,
lib/active_job/traffic_control/base.rb,
lib/active_job/traffic_control/disable.rb,
lib/active_job/traffic_control/version.rb,
lib/active_job/traffic_control/throttle.rb,
lib/active_job/traffic_control/concurrency.rb
Defined Under Namespace
Modules: Base, Concurrency, Disable, Throttle
Constant Summary
collapse
- VERSION =
"0.1.3"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.cache_client ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/active_job/traffic_control.rb', line 19
def cache_client
@cache_client ||= begin
if defined?(Rails.cache)
Rails.cache
else
logger.error "defaulting to `ActiveSupport::Cache::MemoryStore`; please set"\
" `ActiveJob::TrafficControl.cache_client` to a `ActiveSupport::Cache` compatible class."
ActiveSupport::Cache::MemoryStore.new
end
end
end
|
.client_klass ⇒ Object
Returns the value of attribute client_klass.
17
18
19
|
# File 'lib/active_job/traffic_control.rb', line 17
def client_klass
@client_klass
end
|
Class Method Details
.client ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/active_job/traffic_control.rb', line 35
def client
@client ||= begin
logger.error "defaulting to Redis as the lock client; please set "\
" `ActiveJob::TrafficControl.client` to a Redis or Memcached client."
@client_klass = Suo::Client::Redis
Redis.new(url: ENV["REDIS_URL"])
end
end
|
.client=(cli) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/active_job/traffic_control.rb', line 44
def client=(cli)
@client = cli
if client.respond_to?(:checkout) unwrapped_client = client.checkout
@client_klass = client_class_type(unwrapped_client)
client.checkin
else
@client_klass = client_class_type(client)
end
client
end
|
.client_class_type(client) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/active_job/traffic_control.rb', line 58
def client_class_type(client)
if client.instance_of?(Dalli::Client)
Suo::Client::Memcached
elsif client.instance_of?(::Redis)
Suo::Client::Redis
else
raise ArgumentError, "Unsupported client type: #{client}"
end
end
|
.logger ⇒ Object
31
32
33
|
# File 'lib/active_job/traffic_control.rb', line 31
def logger
ActiveJob::Base.logger
end
|