Class: RocketJob::ThreadWorker
- Defined in:
- lib/rocket_job/thread_worker.rb
Overview
ThreadWorker
A worker runs on a single operating system thread. Is usually started under a Rocket Job server process.
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Attributes inherited from Worker
#current_filter, #id, #name, #server_name
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #backtrace ⇒ Object
-
#initialize(id:, server_name:) ⇒ ThreadWorker
constructor
A new instance of ThreadWorker.
- #join(*args) ⇒ Object
-
#kill ⇒ Object
Send each active worker the RocketJob::ShutdownException so that stops processing immediately.
- #shutdown! ⇒ Object
- #shutdown? ⇒ Boolean
-
#wait_for_shutdown?(timeout = nil) ⇒ Boolean
Returns [true|false] whether the shutdown indicator was set.
Methods inherited from Worker
#add_to_current_filter, #find_and_assign_job, #next_available_job, #random_wait_interval, #reset_filter_if_expired, #run, #throttled_job?
Constructor Details
#initialize(id:, server_name:) ⇒ ThreadWorker
Returns a new instance of ThreadWorker.
10 11 12 13 14 |
# File 'lib/rocket_job/thread_worker.rb', line 10 def initialize(id:, server_name:) super(id: id, server_name: server_name) @shutdown = Concurrent::Event.new @thread = Thread.new { run } end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
8 9 10 |
# File 'lib/rocket_job/thread_worker.rb', line 8 def thread @thread end |
Instance Method Details
#alive? ⇒ Boolean
16 17 18 |
# File 'lib/rocket_job/thread_worker.rb', line 16 def alive? @thread.alive? end |
#backtrace ⇒ Object
20 21 22 |
# File 'lib/rocket_job/thread_worker.rb', line 20 def backtrace @thread.backtrace end |
#join(*args) ⇒ Object
24 25 26 |
# File 'lib/rocket_job/thread_worker.rb', line 24 def join(*args) @thread.join(*args) end |
#kill ⇒ Object
Send each active worker the RocketJob::ShutdownException so that stops processing immediately.
29 30 31 |
# File 'lib/rocket_job/thread_worker.rb', line 29 def kill @thread.raise(Shutdown, "Shutdown due to kill request for worker: #{name}") if @thread.alive? end |
#shutdown! ⇒ Object
37 38 39 |
# File 'lib/rocket_job/thread_worker.rb', line 37 def shutdown! @shutdown.set end |
#shutdown? ⇒ Boolean
33 34 35 |
# File 'lib/rocket_job/thread_worker.rb', line 33 def shutdown? @shutdown.set? end |
#wait_for_shutdown?(timeout = nil) ⇒ Boolean
Returns [true|false] whether the shutdown indicator was set
42 43 44 |
# File 'lib/rocket_job/thread_worker.rb', line 42 def wait_for_shutdown?(timeout = nil) @shutdown.wait(timeout) end |