Class: SolidObserver::QueueEvent
- Defined in:
- app/models/solid_observer/queue_event.rb
Constant Summary collapse
- EVENT_TYPES =
%w[ job_enqueued job_completed job_failed job_discarded ].freeze
- DISTINCT_FILTER_LIMIT =
500
Class Method Summary collapse
- .avg_duration_last(duration) ⇒ Object
- .count_by_queue_and_event_type(window:, event_type:) ⇒ Object
- .count_by_time_bucket(event_type:, window:, bucket_seconds:) ⇒ Object
- .enqueue_rate_per_minute(window: 5.minutes) ⇒ Object
- .enqueued_count_last(duration) ⇒ Object
- .failed_count_last(duration) ⇒ Object
- .performed_count_last(duration) ⇒ Object
Class Method Details
.avg_duration_last(duration) ⇒ Object
61 62 63 |
# File 'app/models/solid_observer/queue_event.rb', line 61 def self.avg_duration_last(duration) by_event_type("job_completed").since(duration.ago).average(:duration).to_f end |
.count_by_queue_and_event_type(window:, event_type:) ⇒ Object
65 66 67 68 69 70 71 |
# File 'app/models/solid_observer/queue_event.rb', line 65 def self.count_by_queue_and_event_type(window:, event_type:) since(window.ago) .where(event_type: event_type) .where.not(queue_name: nil) .group(:queue_name) .count end |
.count_by_time_bucket(event_type:, window:, bucket_seconds:) ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/models/solid_observer/queue_event.rb', line 73 def self.count_by_time_bucket(event_type:, window:, bucket_seconds:) context = build_bucket_context(window: window, bucket_seconds: bucket_seconds) return [] unless context counts_by_bucket = fetch_counts_by_bucket(event_type: event_type, context: context) fill_missing_buckets(context: context, counts_by_bucket: counts_by_bucket) end |
.enqueue_rate_per_minute(window: 5.minutes) ⇒ Object
50 51 52 53 54 55 |
# File 'app/models/solid_observer/queue_event.rb', line 50 def self.enqueue_rate_per_minute(window: 5.minutes) count = by_event_type("job_enqueued").since(window.ago).count return 0.0 if count.zero? (count.to_f / (window.to_f / 60.0)).round(1) end |
.enqueued_count_last(duration) ⇒ Object
57 58 59 |
# File 'app/models/solid_observer/queue_event.rb', line 57 def self.enqueued_count_last(duration) by_event_type("job_enqueued").since(duration.ago).count end |
.failed_count_last(duration) ⇒ Object
46 47 48 |
# File 'app/models/solid_observer/queue_event.rb', line 46 def self.failed_count_last(duration) by_event_type("job_failed").since(duration.ago).count end |
.performed_count_last(duration) ⇒ Object
42 43 44 |
# File 'app/models/solid_observer/queue_event.rb', line 42 def self.performed_count_last(duration) by_event_type("job_completed").since(duration.ago).count end |