Class: Async::Background::Web::MetricsReader
- Inherits:
-
Object
- Object
- Async::Background::Web::MetricsReader
- Includes:
- Clock
- Defined in:
- lib/async/background/web/metrics_reader.rb
Constant Summary collapse
- DEFAULT_TTL =
1.0- EMPTY_WORKERS =
[].freeze
- EMPTY_TOTALS =
{ total_runs: 0, total_successes: 0, total_failures: 0, total_timeouts: 0, total_skips: 0, active_jobs: 0, last_run_at: 0, last_duration_ms: nil }.freeze
Instance Method Summary collapse
- #aggregated ⇒ Object
-
#initialize(path:, total_workers:, ttl: DEFAULT_TTL) ⇒ MetricsReader
constructor
A new instance of MetricsReader.
Constructor Details
#initialize(path:, total_workers:, ttl: DEFAULT_TTL) ⇒ MetricsReader
Returns a new instance of MetricsReader.
25 26 27 28 29 30 31 32 |
# File 'lib/async/background/web/metrics_reader.rb', line 25 def initialize(path:, total_workers:, ttl: DEFAULT_TTL) @path = path @total_workers = total_workers @ttl = ttl @mutex = Mutex.new @cache = nil @cached_at = nil end |
Instance Method Details
#aggregated ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/async/background/web/metrics_reader.rb', line 34 def aggregated @mutex.synchronize do now = monotonic_now return @cache if cache_current?(now) @cache = read_metrics.freeze @cached_at = now @cache end end |