Class: SidekiqTamer::Middleware
- Inherits:
-
Object
- Object
- SidekiqTamer::Middleware
show all
- Defined in:
- lib/sidekiq_tamer/middleware.rb
Defined Under Namespace
Classes: ResourceUnhealthy
Instance Method Summary
collapse
Instance Method Details
#call(worker, job, queue) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/sidekiq_tamer/middleware.rb', line 7
def call(worker, job, queue)
Thread.current[:sidekiq_tamer_job_name] = job["class"]
if job_allows_retries?(job)
SidekiqTamer::Resource::Vault.get_resources_for(Object.const_get(job["class"])).each { |resource|
unless resource.is_healthy?
raise ResourceUnhealthy, "#{resource.name} is not healthy"
end
}
end
yield
end
|
#job_allows_retries?(job) ⇒ Boolean
19
20
21
22
23
24
25
|
# File 'lib/sidekiq_tamer/middleware.rb', line 19
def job_allows_retries?(job)
(job["retry_count"] || -1) + 1 < max_retries_for(job)
end
|
#max_retries_for(job) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/sidekiq_tamer/middleware.rb', line 27
def max_retries_for(job)
if job["retry"] == true || job["retry"] == nil
Sidekiq.options[:max_retries] || 25
elsif job["retry"] == false
0
elsif job["retry"].is_a?(Integer)
job["retry"]
else
raise StandardError, "Unrecognized retry option"
end
end
|