Class: FlowTask
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- FlowTask
- Defined in:
- lib/app/models/flow_task.rb
Instance Method Summary collapse
-
#run_command(cmd) ⇒ Object
Runs a system command with logging, captures STDIN, STDOUT, and STDERR and returns them.
- #status ⇒ Object
-
#to_param ⇒ Object
to be used as the friendly URL.
Instance Method Details
#run_command(cmd) ⇒ Object
Runs a system command with logging, captures STDIN, STDOUT, and STDERR and returns them
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/app/models/flow_task.rb', line 34 def run_command(cmd) require 'open3' Rails.logger.info "[INFO #{Time.now}] #{self} running #{cmd}" update_attribute(:command, cmd) stdin, stdout, stderr = Open3.popen3(cmd) [stdin, stdout, stderr].map do |io| s = io.read.strip rescue nil io.close s end end |
#status ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/app/models/flow_task.rb', line 21 def status if error_msg.present? "error" elsif finished_at.present? "done" elsif started_at.present? "working" else "start" end end |
#to_param ⇒ Object
to be used as the friendly URL
17 18 19 |
# File 'lib/app/models/flow_task.rb', line 17 def to_param "#{id}-#{self.class.to_s.underscore}" end |