Class: OmniBot::PeriodicCommand
- Inherits:
-
Object
- Object
- OmniBot::PeriodicCommand
- Includes:
- LoggedCommand
- Defined in:
- lib/omnibot/periodiccommand.rb
Overview
Send to jabber user result of a daily command
Instance Attribute Summary collapse
-
#startup_pause ⇒ Object
writeonly
Sets the attribute startup_pause.
-
#timer_provider ⇒ Object
writeonly
Sets the attribute timer_provider.
Instance Method Summary collapse
-
#initialize(command) ⇒ PeriodicCommand
constructor
A new instance of PeriodicCommand.
- #on_first_timer ⇒ Object
- #on_periodic_timer ⇒ Object
- #start ⇒ Object
- #to_s ⇒ Object
Methods included from LoggedCommand
#jabber_logged_command, #set_jabber_messenger
Constructor Details
#initialize(command) ⇒ PeriodicCommand
Returns a new instance of PeriodicCommand.
28 29 30 31 32 33 |
# File 'lib/omnibot/periodiccommand.rb', line 28 def initialize command @command = command @startup_pause = 0 raise 'Wrong command' if (@command or '') == '' end |
Instance Attribute Details
#startup_pause=(value) ⇒ Object (writeonly)
Sets the attribute startup_pause
26 27 28 |
# File 'lib/omnibot/periodiccommand.rb', line 26 def startup_pause=(value) @startup_pause = value end |
#timer_provider=(value) ⇒ Object (writeonly)
Sets the attribute timer_provider
25 26 27 |
# File 'lib/omnibot/periodiccommand.rb', line 25 def timer_provider=(value) @timer_provider = value end |
Instance Method Details
#on_first_timer ⇒ Object
10 11 12 13 |
# File 'lib/omnibot/periodiccommand.rb', line 10 def on_first_timer on_periodic_timer @timer_provider.add_periodic_timer(24*3600) { on_periodic_timer } end |
#on_periodic_timer ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/omnibot/periodiccommand.rb', line 15 def on_periodic_timer begin OmniLog::info "Reporting command #{@command}" jabber_logged_command 'Periodic command', @command rescue => e OmniLog::error "PeriodicCommand error: #{e.}\ntrace:\n#{Helpers::backtrace e}" end end |
#start ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/omnibot/periodiccommand.rb', line 39 def start now = Time.now tomorrow = DateTime.now+1 next_report_time = Time.local(tomorrow.year, tomorrow.month, tomorrow.day, 1, 0, 0) next_report_time = next_report_time + @startup_pause @timer_provider.add_timer(next_report_time - now) { on_first_timer } end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/omnibot/periodiccommand.rb', line 35 def to_s "Periodic command '#{@command}'" end |