Class: Karafka::Pro::ScheduledMessages::Tracker
- Inherits:
-
Object
- Object
- Karafka::Pro::ScheduledMessages::Tracker
- Defined in:
- lib/karafka/pro/scheduled_messages/tracker.rb
Overview
Tracks basic state and metrics about schedules to be dispatched
It provides accurate today dispatch taken from daily buffer and estimates for future days
Instance Attribute Summary collapse
- #daily ⇒ Hash<String, Integer> readonly
-
#state ⇒ String
Current state.
Instance Method Summary collapse
-
#initialize ⇒ Tracker
constructor
A new instance of Tracker.
-
#today=(sum) ⇒ Object
Accurate (because coming from daily buffer) number of things to schedule.
-
#track(message) ⇒ Object
Tracks message dispatch.
Constructor Details
#initialize ⇒ Tracker
Returns a new instance of Tracker.
27 28 29 30 |
# File 'lib/karafka/pro/scheduled_messages/tracker.rb', line 27 def initialize @daily = Hash.new { |h, k| h[k] = 0 } @created_at = Time.now.to_i end |
Instance Attribute Details
#daily ⇒ Hash<String, Integer> (readonly)
22 23 24 |
# File 'lib/karafka/pro/scheduled_messages/tracker.rb', line 22 def daily @daily end |
#state ⇒ String
Returns current state.
25 26 27 |
# File 'lib/karafka/pro/scheduled_messages/tracker.rb', line 25 def state @state end |
Instance Method Details
#today=(sum) ⇒ Object
Accurate (because coming from daily buffer) number of things to schedule
35 36 37 |
# File 'lib/karafka/pro/scheduled_messages/tracker.rb', line 35 def today=(sum) @daily[epoch_to_date(@created_at)] = sum end |
#track(message) ⇒ Object
Tracks message dispatch
It is only relevant for future days as for today we use accurate metrics from the daily buffer
48 49 50 51 52 |
# File 'lib/karafka/pro/scheduled_messages/tracker.rb', line 48 def track() epoch = .headers['schedule_target_epoch'] @daily[epoch_to_date(epoch)] += 1 end |