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 48 |
# 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 = ?", Delayed::Backend::Base::ON_HOLD_LOCKED_BY) # not running .group(:queue) 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
33 34 35 36 37 38 39 40 41 |
# File 'lib/inst_jobs_statsd/stats/periodic/queue.rb', line 33 def self.report_queue_age jobs_run_at_by_queue = queued_jobs_scope.limit(10_000).pluck(:queue, "ARRAY_AGG(run_at)").to_h age_secs_by_queue = jobs_run_at_by_queue.transform_values { |v| v.map { |t| Delayed::Job.db_time_now - t } } age_max_by_queue = age_secs_by_queue.transform_values(&:max) age_total_by_queue = age_secs_by_queue.transform_values(&:sum) Periodic.report_gauge_by_queue(:queue_age_total, age_total_by_queue) Periodic.report_gauge_by_queue(:queue_age_max, age_max_by_queue) end |
.report_queue_depth ⇒ Object
22 23 24 |
# File 'lib/inst_jobs_statsd/stats/periodic/queue.rb', line 22 def self.report_queue_depth Periodic.report_gauge_by_queue(:queue_depth, queued_jobs_scope.count) end |