Method: Temporalio::Worker#shutdown
- Defined in:
- lib/temporalio/worker.rb
#shutdown(exception = Temporalio::Error::WorkerShutdown.new('Manual shutdown')) ⇒ Object
Initiate a worker shutdown and wait until complete.
This can be called before the worker has even started and is safe for repeated invocations. This method will not return until the worker has completed shutting down.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/temporalio/worker.rb', line 161 def shutdown(exception = Temporalio::Error::WorkerShutdown.new('Manual shutdown')) mutex.synchronize do return unless running? # Let the runner know we're shutting down, so it can stop other workers. # This will cause a reentrant call to this method, but the mutex above will block that call. runner&.shutdown(exception) # Initiate Core shutdown, which will start dropping poll requests core_worker.initiate_shutdown # Start the graceful activity shutdown timer, which will cancel activities after the timeout activity_worker&.setup_graceful_shutdown_timer(runtime.reactor) # Wait for workers to drain any outstanding tasks activity_worker&.drain activity_executor.shutdown # Finalize the shutdown by stopping the Core core_worker.finalize_shutdown @shutdown = true end end |