Skip to content

Commit e3c6666

Browse files
committed
Fix(ci): Refactor worker shutdown logic into helper method
Moved the worker shutdown code into a new _shutdown_workers() method in ProcessManager to improve code reuse and readability. The start() method now calls this helper when handling ShutdownAction.
1 parent d5c8198 commit e3c6666

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

taskiq/cli/worker/process_manager.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ def prepare_workers(self) -> None:
214214
for worker, event in zip(self.workers, events, strict=True):
215215
_wait_for_worker_startup(worker, event)
216216

217+
def _shutdown_workers(self) -> None:
218+
for worker in self.workers:
219+
if worker.pid:
220+
try:
221+
os.kill(worker.pid, signal.SIGINT)
222+
logger.info(
223+
"Stopped process %s with pid %s",
224+
worker.name,
225+
worker.pid,
226+
)
227+
except ProcessLookupError:
228+
logger.info(
229+
"Process %s (pid %s) already terminated",
230+
worker.name,
231+
worker.pid,
232+
)
233+
217234
def start(self) -> int | None: # noqa: C901
218235
"""
219236
Start managing child processes.
@@ -273,21 +290,7 @@ def start(self) -> int | None: # noqa: C901
273290
reloaded_workers.add(action.worker_num)
274291
elif isinstance(action, ShutdownAction):
275292
logger.debug("Process manager closed, killing workers.")
276-
for worker in self.workers:
277-
if worker.pid:
278-
try:
279-
os.kill(worker.pid, signal.SIGINT)
280-
logger.info(
281-
"Stopped process %s with pid %s",
282-
worker.name,
283-
worker.pid,
284-
)
285-
except ProcessLookupError:
286-
logger.info(
287-
"Process %s (pid %s) already terminated",
288-
worker.name,
289-
worker.pid,
290-
)
293+
self._shutdown_workers()
291294
return None
292295

293296
for worker_num, worker in enumerate(self.workers):

0 commit comments

Comments
 (0)