Class: FlowTask

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/app/models/flow_task.rb

Instance Method Summary collapse

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

#statusObject



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_paramObject

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