Sha256: f1b66008e704064689c56addeecbcb71c205abce3ffdce3fb0f880599745dc8e
Contents?: true
Size: 1022 Bytes
Versions: 12
Compression:
Stored size: 1022 Bytes
Contents
require "concurrent" module RocketJob # ThreadWorker # # A worker runs on a single operating system thread. # Is usually started under a Rocket Job server process. class ThreadWorker < Worker attr_reader :thread def initialize(id:, server_name:) super(id: id, server_name: server_name) @shutdown = Concurrent::Event.new @thread = Thread.new { run } end def alive? @thread.alive? end def backtrace @thread.backtrace end def join(*args) @thread.join(*args) end # Send each active worker the RocketJob::ShutdownException so that stops processing immediately. def kill @thread.raise(Shutdown, "Shutdown due to kill request for worker: #{name}") if @thread.alive? end def shutdown? @shutdown.set? end def shutdown! @shutdown.set end # Returns [true|false] whether the shutdown indicator was set def wait_for_shutdown?(timeout = nil) @shutdown.wait(timeout) end end end
Version data entries
12 entries across 12 versions & 1 rubygems