lib/detached_workers.rb
# Maximum of ten worker threads per worker process
Maximum of ten worker threads per worker process
Maximum of ten worker threads per worker process
def perform_tasks
      return unless @tasks.size > 0
      DetachedWorkers.worker_pre_fork.execute
      return @pid unless (@pid = fork).nil?
      Signal.trap("TERM") { @work_queue.stop; exit! }
      Signal.trap("INT") { @work_queue.stop; exit! }
      DetachedWorkers.worker_post_fork.execute
      Process.setpriority(Process::PRIO_PROCESS, 0, DetachedWorkers.worker_priority)
      @pid = $$
      $0 = '__worker__'
      @tasks.each do |task|
        @work_queue.enqueue_b {
          puts "Executing Task in worker[#{@pid}] with args: #{task.args.inspect}" if DetachedWorkers.debug?
          task.execute
          puts "Finished Task in worker[#{@pid}]  with args: #{task.args.inspect}" if DetachedWorkers.debug?
        }
      end
      @work_queue.join
      exit! 
    end
def perform_tasks return unless @tasks . size > 0 DetachedWorkers . worker_pre_fork . execute return @pid unless ( @pid = fork ) . nil? Signal . trap ( "TERM" ) { @work_queue . stop ; exit! } Signal . trap ( "INT" ) { @work_queue . stop ; exit! } DetachedWorkers . worker_post_fork . execute Process . setpriority ( Process :: PRIO_PROCESS , 0 , DetachedWorkers . worker_priority ) @pid = $$ $0 = '__worker__' @tasks . each do | task | @work_queue . enqueue_b { puts "Executing Task in worker[#{@pid}] with args: #{task.args.inspect}" if DetachedWorkers . debug? task . execute puts "Finished Task in worker[#{@pid}]  with args: #{task.args.inspect}" if DetachedWorkers . debug? } end @work_queue . join exit! end
Maximum of ten worker threads per worker process
Maximum of ten worker threads per worker process
# return to parent after fork, unless we're in the child # once the tasks are finished, exit! # note: we MUST exit our child with exit! or # we'll end up call our "at_exit" above..