WorkerShutdownMode enum
Shutdown modes for workers.
Controls how the worker terminates when Worker.shutdown is called. Each mode offers different trade-offs between task completion and shutdown speed.
Mode Comparison
| Mode | In-Flight Tasks | New Tasks | Grace Period |
|---|---|---|---|
| warm | Complete | Rejected | None |
| soft | Terminate cooperatively | Rejected | Yes |
| hard | Cancelled immediately | Rejected | None |
Example
// For deployments: let tasks finish but stop accepting new work
await worker.shutdown(mode: WorkerShutdownMode.warm);
// For updates: give tasks time to checkpoint
await worker.shutdown(mode: WorkerShutdownMode.soft);
// For emergencies: stop immediately
await worker.shutdown(mode: WorkerShutdownMode.hard);
Values
- warm → const WorkerShutdownMode
-
Allows in-flight tasks to complete without draining new work.
The worker stops accepting new deliveries immediately but waits indefinitely for currently running tasks to finish. Use this for graceful deployments when tasks are short-lived.
- soft → const WorkerShutdownMode
-
Drains the worker before shutting down.
Requests cooperative termination of running tasks by signaling them via TaskContext. If tasks don't terminate within WorkerLifecycleConfig.softGracePeriod, escalates to hard shutdown.
Tasks can check for termination requests by calling
context.checkTermination()periodically. - hard → const WorkerShutdownMode
-
Immediately stops and cancels active work.
All running tasks are cancelled immediately and their deliveries are requeued to the broker (if supported). Use this for emergencies or when tasks are safe to retry from the beginning.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- index → int
-
A numeric identifier for the enumerated value.
no setterinherited
- name → String
-
Available on Enum, provided by the EnumName extension
The name of the enum value.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
-
values
→ const List<
WorkerShutdownMode> - A constant List of the values in this enum, in order of their declaration.