Class: Enparallel::Task
- Inherits:
- 
      Object
      
        - Object
- Enparallel::Task
 
- Defined in:
- lib/enparallel/task.rb
Instance Attribute Summary collapse
- 
  
    
      #stderr  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute stderr. 
- 
  
    
      #stdout  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute stdout. 
Instance Method Summary collapse
- #char ⇒ Object
- 
  
    
      #initialize(command, input)  ⇒ Task 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Task. 
- #run ⇒ Object
- #succeeded? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(command, input) ⇒ Task
Returns a new instance of Task.
| 6 7 8 9 10 11 12 13 14 | # File 'lib/enparallel/task.rb', line 6 def initialize(command, input) @command = command @input = input @running = false @stdout = '' @stderr = '' @ran_at = nil @exit_status = nil end | 
Instance Attribute Details
#stderr ⇒ Object
Returns the value of attribute stderr.
| 4 5 6 | # File 'lib/enparallel/task.rb', line 4 def stderr @stderr end | 
#stdout ⇒ Object
Returns the value of attribute stdout.
| 3 4 5 | # File 'lib/enparallel/task.rb', line 3 def stdout @stdout end | 
Instance Method Details
#char ⇒ Object
| 28 29 30 31 32 33 34 35 36 37 38 | # File 'lib/enparallel/task.rb', line 28 def char if @running 'R' elsif @exit_status.nil? 'S' elsif succeeded? 'D'.green else 'F'.red end end | 
#run ⇒ Object
| 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # File 'lib/enparallel/task.rb', line 40 def run @running = true @ran_at = Time.now Open3.popen3(command_line_safe) do |_stdin, stdout, stderr, thread| @stdout = stdout.read.chomp @stderr = stderr.read.chomp @exit_status = thread.value.exitstatus end rescue => e @stderr = e. @exit_status = 1 ensure @running = false end | 
#succeeded? ⇒ Boolean
| 56 57 58 59 60 | # File 'lib/enparallel/task.rb', line 56 def succeeded? raise 'Task not resolved' if @ran_at.nil? @exit_status == 0 end | 
#to_s ⇒ Object
| 16 17 18 19 20 21 22 23 24 25 26 | # File 'lib/enparallel/task.rb', line 16 def to_s document = SOML::Document.new document.add('CommandLine', command_line_unsafe) document.add('ExitStatus', @exit_status) document.add('RanAt', @ran_at) document.add('StandardOutput', @stdout) unless @stdout.empty? document.add('StandardError', @stderr) unless @stderr.empty? document.to_s end |