Module: Yabeda::Sidekiq
- Defined in:
- lib/yabeda/sidekiq.rb,
lib/yabeda/sidekiq/config.rb,
lib/yabeda/sidekiq/version.rb,
lib/yabeda/sidekiq/client_middleware.rb,
lib/yabeda/sidekiq/server_middleware.rb
Defined Under Namespace
Classes: ClientMiddleware, Config, ServerMiddleware
Constant Summary
collapse
- LONG_RUNNING_JOB_RUNTIME_BUCKETS =
[
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 120, 300, 1800, 3600, 21_600, ].freeze
- VERSION =
"0.12.0"
Class Attribute Summary collapse
-
.jobs_started_at ⇒ Object
Hash of hashes containing all currently running jobs’ start timestamps to calculate maximum durations of currently running not yet completed jobs { { queue: “default”, worker: “SomeJob” } => { “jid1” => 100500, “jid2” => 424242 } }.
Class Method Summary
collapse
Class Attribute Details
.jobs_started_at ⇒ Object
Hash of hashes containing all currently running jobs’ start timestamps to calculate maximum durations of currently running not yet completed jobs { { queue: “default”, worker: “SomeJob” } => { “jid1” => 100500, “jid2” => 424242 } }
134
135
136
|
# File 'lib/yabeda/sidekiq.rb', line 134
def jobs_started_at
@jobs_started_at
end
|
Class Method Details
.config ⇒ Object
19
20
21
|
# File 'lib/yabeda/sidekiq.rb', line 19
def self.config
@config ||= Config.new
end
|
125
126
127
128
129
|
# File 'lib/yabeda/sidekiq.rb', line 125
def custom_tags(worker, job)
return {} unless worker.respond_to?(:yabeda_tags)
worker.method(:yabeda_tags).arity.zero? ? worker.yabeda_tags : worker.yabeda_tags(*job["args"])
end
|
.labelize(worker, job, queue) ⇒ Object
116
117
118
|
# File 'lib/yabeda/sidekiq.rb', line 116
def labelize(worker, job, queue)
{ queue: queue, worker: worker_class(worker, job) }
end
|
.track_max_job_runtime ⇒ Object
136
137
138
139
140
141
142
143
|
# File 'lib/yabeda/sidekiq.rb', line 136
def track_max_job_runtime
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
::Yabeda::Sidekiq.jobs_started_at.each do |labels, jobs|
oldest_job_started_at = jobs.values.min
oldest_job_duration = oldest_job_started_at ? (now - oldest_job_started_at).round(3) : 0
Yabeda.sidekiq.running_job_runtime.set(labels, oldest_job_duration)
end
end
|
.worker_class(worker, job) ⇒ Object
120
121
122
123
|
# File 'lib/yabeda/sidekiq.rb', line 120
def worker_class(worker, job)
worker = job["wrapped"] || worker
(worker.is_a?(String) || worker.is_a?(Class) ? worker : worker.class).to_s
end
|