Class: DynarexCron
- Inherits:
-
Object
- Object
- DynarexCron
- Defined in:
- lib/dynarex_cron.rb
Instance Method Summary collapse
-
#initialize(dxfile = nil, sps_address: 'sps', sps_port: '59000', log: nil, time_offset: 0, logtopic: 'DynarexCron', debug: false) ⇒ DynarexCron
constructor
options: e.g.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(dxfile = nil, sps_address: 'sps', sps_port: '59000', log: nil, time_offset: 0, logtopic: 'DynarexCron', debug: false) ⇒ DynarexCron
options: e.g. sps_address: 'sps', sps_port: '59000'
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dynarex_cron.rb', line 18 def initialize(dxfile=nil, sps_address: 'sps', sps_port: '59000', \ log: nil, time_offset: 0, logtopic: 'DynarexCron', debug: false) @dxfile, @sps_address, @sps_port, @log = dxfile, sps_address, sps_port, log # time_offset: used for testing a cron entry without having to change # the time of each entry @time_offset = time_offset.to_i @cron_entries = [] @logtopic = logtopic if @dxfile then dynarex,_ = load_doc dxfile load_entries(dynarex) end @pub = SPSPub.new address: sps_address, port: sps_port end |
Instance Method Details
#start ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dynarex_cron.rb', line 42 def start @running = true if @log then @log.info @logtopic + '/start: Time.now: ' \ + (Time.now + @time_offset).strftime(DF) end sleep 1 until Time.now.sec == 0 # the following loop runs every minute while true do iterate @cron_entries if @dxfile.is_a? String then # What happens if the @dxfile is a URL and the web server is # temporarily unavailable? i.e. 503 Service Temporarily Unavailable begin dx, buffer = load_doc(@dxfile) load_entries dx if @buffer != buffer @buffer = buffer rescue @log.debug @logtopic + '/start: warning: ' + ($!).inspect if @log end end min = Time.now.min sleep 1 sleep 1 until Time.now.sec < 10 and Time.now.min != min end end |
#stop ⇒ Object
82 83 84 |
# File 'lib/dynarex_cron.rb', line 82 def stop() @running = false end |