class ChronoTrigger::Clock
Attributes
status[R]
ticks[R]
Public Class Methods
init()
click to toggle source
# File lib/chrono_trigger/clock.rb, line 8 def init @ticks = 0 @status ||= :stopped end
start()
click to toggle source
# File lib/chrono_trigger/clock.rb, line 13 def start init if stopped? last_tick = Time.zone.now Rails.logger.info "ChronoTrigger: Clock started with a #{ChronoTrigger.config.interval}s interval" ChronoTrigger.schedule.refresh task = Concurrent::TimerTask.new(execution_interval: ChronoTrigger.config.interval) do |task| if Time.zone.now - last_tick >= 1 last_tick += 1 @ticks += 1 ChronoTrigger.schedule.process_events end task.shutdown if stopped? end task.execute end @status = :started end
stop()
click to toggle source
# File lib/chrono_trigger/clock.rb, line 33 def stop if ticking? Rails.logger.info "ChronoTrigger: Timer stopped" @status = :stopped end @status end
stopped?()
click to toggle source
# File lib/chrono_trigger/clock.rb, line 45 def stopped? @status == :stopped end
ticking?()
click to toggle source
# File lib/chrono_trigger/clock.rb, line 41 def ticking? @status == :started end