Module: Postburner::Statistics
- Extended by:
- ActiveSupport::Concern
- Included in:
- Job
- Defined in:
- app/concerns/postburner/statistics.rb
Overview
Concern providing statistics and metrics methods for Postburner jobs.
Provides methods for calculating timing metrics, retrieving job statistics, and determining intended execution times for scheduled jobs.
Instance Method Summary collapse
-
#elapsed_ms ⇒ Float?
Returns elapsed time in milliseconds since job execution started.
-
#intended_at ⇒ Time
Returns the intended execution time for the job.
-
#stats ⇒ Hash
Returns job statistics including Beanstalkd job state.
Instance Method Details
#elapsed_ms ⇒ Float?
Returns elapsed time in milliseconds since job execution started.
Calculates milliseconds between attempting_at and current time. Used to track how long a job has been executing.
100 101 102 103 |
# File 'app/concerns/postburner/statistics.rb', line 100 def elapsed_ms return unless self.attempting_at (Time.current - self.attempting_at) * 1000 end |
#intended_at ⇒ Time
Returns the intended execution time for the job.
Returns run_at if scheduled, otherwise returns queued_at. Used for calculating lag (delay between intended and actual execution).
121 122 123 |
# File 'app/concerns/postburner/statistics.rb', line 121 def intended_at self.run_at ? self.run_at : self.queued_at end |
#stats ⇒ Hash
Returns job statistics including Beanstalkd job state.
Fetches current job state from Beanstalkd and returns combined statistics about the job’s PostgreSQL record and its current Beanstalkd status.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/concerns/postburner/statistics.rb', line 74 def stats # Get configured watched tubes (expanded with environment prefix) watched = Postburner.watched_tube_names.include?(self.tube_name) { id: self.id, bkid: self.bkid, queue: queue_name, tube: tube_name, watched: watched, beanstalk: self.bk.stats.to_h.symbolize_keys, } end |