Class: SystemJobs

Inherits:
JobQueue show all
Defined in:
lib/jobqueue.rb

Overview

Special class for runing operating system commands with Ruby’s system call

Instance Attribute Summary

Attributes inherited from JobQueue

#threads, #workers

Instance Method Summary collapse

Methods inherited from JobQueue

#initialize, maxnumber_of_processors, #push

Constructor Details

This class inherits a constructor from JobQueue

Instance Method Details

#runObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/jobqueue.rb', line 94

def run
  @threads = (1..@workers).map {|i|
    Thread.new(@queue,@debug) {|q,dbg|
      until ( q == ( task = q.deq ) )
        _, stdout, stderr, _ = Open3.popen3(task.first)

        # Create a thread to read from each stream
        [stdout,stderr].map {|stdio|
          Thread.new { puts $_ until stdio.gets.nil? }
        }.each {|t| t.join} if dbg
      end
    }
  }
  @threads.size.times { @queue.enq @queue}
  @threads.each {|t| t.join}
end