Class: Leafy::Core::ScheduledReporter::ReportedTask

Inherits:
Object
  • Object
show all
Defined in:
lib/leafy/core/scheduled_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reporter, start, period) ⇒ ReportedTask

Returns a new instance of ReportedTask.



37
38
39
40
41
# File 'lib/leafy/core/scheduled_reporter.rb', line 37

def initialize(reporter, start, period)
  @reporter = reporter
  @start = start
  @period = period
end

Instance Attribute Details

#periodObject (readonly)

Returns the value of attribute period.



35
36
37
# File 'lib/leafy/core/scheduled_reporter.rb', line 35

def period
  @period
end

Instance Method Details

#callObject



47
48
49
# File 'lib/leafy/core/scheduled_reporter.rb', line 47

def call
  @reporter.report
end

#delayObject



43
44
45
# File 'lib/leafy/core/scheduled_reporter.rb', line 43

def delay
  @period - (Concurrent.monotonic_time - @start) % @period
end

#task(task = nil) ⇒ Object



51
52
53
# File 'lib/leafy/core/scheduled_reporter.rb', line 51

def task(task = nil)
  @task ||= task
end

#to_sObject



55
56
57
# File 'lib/leafy/core/scheduled_reporter.rb', line 55

def to_s
  "start: #{Time.at(@start).utc} period: #{@period}"
end