Skip to content

Commit 3ffecae

Browse files
committed
Merge branch 'release/0.11.4'
2 parents d350042 + 945748b commit 3ffecae

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

docs/guide/cli.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ To enable this option simply pass the `--reload` or `-r` option to worker taskiq
8484
Also this option supports `.gitignore` files. If you have such file in your directory, it won't reload worker
8585
when you modify ignored files. To disable this functionality pass `--do-not-use-gitignore` option.
8686

87+
### Graceful reload
88+
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.
90+
91+
```bash
92+
taskiq worker my_module:broker
93+
kill -HUP <main pid>
94+
```
95+
8796
### Other parameters
8897

8998
* `--no-configure-logging` - disables default logging configuration for workers.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "taskiq"
3-
version = "0.11.3"
3+
version = "0.11.4"
44
description = "Distributed task queue with full async support"
55
authors = ["Pavel Kirilin <[email protected]>"]
66
maintainers = ["Pavel Kirilin <[email protected]>"]

taskiq/cli/worker/process_manager.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def schedule_workers_reload(
118118

119119
def get_signal_handler(
120120
action_queue: "Queue[ProcessActionBase]",
121+
action_to_send: ProcessActionBase,
121122
) -> Callable[[int, Any], None]:
122123
"""
123124
Generate signal handler for main process.
@@ -126,6 +127,7 @@ def get_signal_handler(
126127
the action queue.
127128
128129
:param action_queue: event queue.
130+
:param action_to_send: action that will be sent to the queue on signal.
129131
:returns: actual signal handler.
130132
"""
131133

@@ -134,7 +136,7 @@ def _signal_handler(signum: int, _frame: Any) -> None:
134136
raise KeyboardInterrupt
135137

136138
logger.debug(f"Got signal {signum}.")
137-
action_queue.put(ShutdownAction())
139+
action_queue.put(action_to_send)
138140
logger.warning("Workers are scheduled for shutdown.")
139141

140142
return _signal_handler
@@ -169,9 +171,13 @@ def __init__(
169171
recursive=True,
170172
)
171173

172-
signal_handler = get_signal_handler(self.action_queue)
173-
signal.signal(signal.SIGINT, signal_handler)
174-
signal.signal(signal.SIGTERM, signal_handler)
174+
shutdown_handler = get_signal_handler(self.action_queue, ShutdownAction())
175+
signal.signal(signal.SIGINT, shutdown_handler)
176+
signal.signal(signal.SIGTERM, shutdown_handler)
177+
signal.signal(
178+
signal.SIGHUP,
179+
get_signal_handler(self.action_queue, ReloadAllAction()),
180+
)
175181

176182
self.workers: List[Process] = []
177183

taskiq/cli/worker/run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import logging
3+
import os
34
import signal
45
from concurrent.futures import ThreadPoolExecutor
56
from multiprocessing import set_start_method
@@ -172,6 +173,7 @@ def run_worker(args: WorkerArgs) -> Optional[int]:
172173
)
173174
logging.getLogger("taskiq").setLevel(level=logging.getLevelName(args.log_level))
174175
logging.getLogger("watchdog.observers.inotify_buffer").setLevel(level=logging.INFO)
176+
logger.info("Pid of a main process: %s", str(os.getpid()))
175177
logger.info("Starting %s worker processes.", args.workers)
176178

177179
observer = None

0 commit comments

Comments
 (0)