Module: Procrastinator::Scheduler::ThreadedWorking

Included in:
DaemonWorking, WorkProxy
Defined in:
lib/procrastinator/scheduler.rb

Overview

Threaded work style

See Also:

Defined Under Namespace

Classes: MultiIO

Constant Summary collapse

PROG_NAME =

Program name. Used as default for pid file names and in logging.

'Procrastinator'

Instance Method Summary collapse

Instance Method Details

#threaded(timeout: nil) ⇒ Object

Work off jobs per queue, each in its own thread.

Parameters:

  • timeout (defaults to: nil)

    Maximum number of seconds to run for. If nil, will run indefinitely.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/procrastinator/scheduler.rb', line 134

def threaded(timeout: nil)
   open_log
   shutdown_on_interrupt

   begin
      @threads = spawn_threads

      @logger.info "#{ PROG_NAME } running. Process ID: #{ Process.pid }"
      @threads.each do |thread|
         thread.join(timeout)
      end
   rescue StandardError => e
      thread_crash(e)
   ensure
      @logger&.info 'Halting worker threads...'
      shutdown!
      @logger&.info 'Threads halted.'
   end
end