Skip to content

Commit e5c6d2b

Browse files
authored
Added correct graceful shutdown. (#381)
1 parent 317c1d9 commit e5c6d2b

File tree

7 files changed

+2448
-1993
lines changed

7 files changed

+2448
-1993
lines changed

docs/guide/cli.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,26 @@ when you modify ignored files. To disable this functionality pass `--do-not-use-
8686

8787
### Graceful reload (available only on Unix systems)
8888

89-
To perform graceful reload, send `SIGHUP` signal to the main worker process. This action will reload all workers with new code. It's useful for deployment that requires zero downtime, but don't use orchestration tools like Kubernetes.
89+
To perform graceful reload, send `SIGHUP` signal to the main worker process. This action will reload all workers with new code. It's useful for deployment that requires zero downtime, but without using heavy orchestration tools like Kubernetes.
90+
9091

9192
```bash
9293
taskiq worker my_module:broker
9394
kill -HUP <main pid>
9495
```
9596

97+
### Graceful and force shutdowns
98+
99+
If you send `SIGINT` or `SIGKILL` to the main process by pressing <kbd>Ctrl</kbd>+<kbd>C</kbd> or using the `kill` command, it will initiate the shutdown process.
100+
By default, it will stop fetching new messages immediately after receiving the signal but will wait for the completion of all currently executing tasks.
101+
102+
If you don't want to wait too long for tasks to complete each time you shut down the worker, you can either send termination signals three times to the main process to perform a hard kill or configure the `--wait-tasks-timeout` to set a hard time limit for shutting down.
103+
104+
::: tip Cool tip
105+
The number of signals before a hard kill can be configured with the `--hardkill-count` CLI argument.
106+
:::
107+
108+
96109
### Other parameters
97110

98111
* `--no-configure-logging` - disables default logging configuration for workers.
@@ -107,6 +120,7 @@ kill -HUP <main pid>
107120
* `max-tasks-per-child` - maximum number of tasks to be executed by a single worker process before restart.
108121
* `--shutdown-timeout` - maximum amount of time for graceful broker's shutdown in seconds.
109122
* `--wait-tasks-timeout` - if cannot read new messages from the broker or maximum number of tasks is reached, worker will wait for all current tasks to finish. This parameter sets the maximum amount of time to wait until shutdown.
123+
* `--hardkill-count` - Number of termination signals to the main process before performing a hardkill.
110124

111125
## Scheduler
112126

0 commit comments

Comments
 (0)