Module: InstJobsStatsd::Stats::Periodic::Queue
- Defined in:
- lib/inst_jobs_statsd/stats/periodic/queue.rb
Class Method Summary collapse
- .enable ⇒ Object
- .enable_queue_age ⇒ Object
- .enable_queue_depth ⇒ Object
- .queued_jobs_scope ⇒ Object
-
.report_queue_age ⇒ Object
Limit the jobs included in this gauge to prevent blowing up memory usage in iterating the list.
- .report_queue_depth ⇒ Object
Class Method Details
.enable ⇒ Object
7 8 9 10 |
# File 'lib/inst_jobs_statsd/stats/periodic/queue.rb', line 7 def self.enable enable_queue_depth enable_queue_age end |
.enable_queue_age ⇒ Object
17 18 19 20 |
# File 'lib/inst_jobs_statsd/stats/periodic/queue.rb', line 17 def self.enable_queue_age Periodic.enable_callbacks Periodic.add(-> { report_queue_age }) end |
.enable_queue_depth ⇒ Object
12 13 14 15 |
# File 'lib/inst_jobs_statsd/stats/periodic/queue.rb', line 12 def self.enable_queue_depth Periodic.enable_callbacks Periodic.add(-> { report_queue_depth }) end |
.queued_jobs_scope ⇒ Object
43 44 45 46 47 |
# File 'lib/inst_jobs_statsd/stats/periodic/queue.rb', line 43 def self.queued_jobs_scope Delayed::Job .current .where("locked_at IS NULL OR locked_by = 'on_hold'") # not running end |
.report_queue_age ⇒ Object
Limit the jobs included in this gauge to prevent blowing up memory usage in iterating the list. This has the adverse effect of artificially capping this metric, but the limit should be high enough so that the the metric still has a meaningful range – and even if the count is capped, the metric will continue to grow if the queue is actually stalled
36 37 38 39 40 41 |
# File 'lib/inst_jobs_statsd/stats/periodic/queue.rb', line 36 def self.report_queue_age jobs_run_at = queued_jobs_scope.limit(10_000).pluck(:run_at) age_secs = jobs_run_at.map { |t| Delayed::Job.db_time_now - t } Periodic.report_gauge(:queue_age_total, age_secs.sum) Periodic.report_gauge(:queue_age_max, age_secs.max || 0) end |
.report_queue_depth ⇒ Object
22 23 24 25 26 27 |
# File 'lib/inst_jobs_statsd/stats/periodic/queue.rb', line 22 def self.report_queue_depth # count = Delayed::Job.jobs_count(:current) <-- includes running / locked scope = queued_jobs_scope count = scope.count Periodic.report_gauge(:queue_depth, count) end |