Class: Schedule::Runner
- Inherits:
-
Object
- Object
- Schedule::Runner
- Defined in:
- lib/schedule/runner.rb
Instance Method Summary collapse
-
#initialize(task, logger = nil, notifier = nil) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
Instance Method Details
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/schedule/runner.rb', line 11 def run @logger.log "=== Started (#{@task.command}) ===" status = nil duration = with_timing do status = execute(@task.command) do |output| buffer = "" begin while (buffer << output.readpartial(1024)) if lines = buffer.slice!(/^.*[\n\r]/m) @logger.log(lines) end end rescue EOFError @logger.log(buffer) unless buffer == "" ensure buffer = nil end end end exit_status = if status && status.exitstatus == 0 0 elsif status && status.exitstatus status.exitstatus else 1 end if exit_status == 0 @logger.log "=== Completed successfully (took #{duration} seconds) ===" else @logger.log "=== Failed (took #{duration} seconds) ===" end if @notifier @notifier.notify(@task, @logger.buffer.string) end return exit_status end |