Skip to content

Commit 33806c6

Browse files
committed
Add optional celery worker restart after N runs, to pyesdl 26.2
1 parent 481fdf6 commit 33806c6

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ authors = [
88
]
99
description = "Python implementation of the OMOTES SDK through jobs which may be submitted, receive status updates for submitted jobs or delete submitted jobs."
1010
readme = "README.md"
11-
license = {file = "LICENSE"}
11+
license = { file = "LICENSE" }
1212
classifiers = [
1313
"License :: OSI Approved :: Apache Software License",
1414
"Programming Language :: Python :: 3",
@@ -26,7 +26,7 @@ classifiers = [
2626
dependencies = [
2727
"aio-pika ~= 9.4, < 9.5",
2828
"omotes-sdk-protocol ~= 1.2",
29-
"pyesdl ~= 25.7",
29+
"pyesdl ~= 26.2",
3030
"pamqp ~= 3.3",
3131
"celery ~= 5.3",
3232
"typing-extensions ~= 4.11",

src/omotes_sdk/internal/worker/configs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class WorkerConfig:
2222
"""Name of the queue to which progress updates for the task should be send."""
2323
log_level: str
2424
"""Log level for any logging in the worker."""
25+
max_tasks_before_restart: int
26+
"""The number of tasks (runs) after which the celery worker will be restarted."""
2527

2628
def __init__(self) -> None:
2729
"""Create the worker config and retrieve values from environment variables."""
@@ -33,3 +35,4 @@ def __init__(self) -> None:
3335
"TASK_PROGRESS_QUEUE_NAME", "omotes_task_progress_events"
3436
)
3537
self.log_level = os.environ.get("LOG_LEVEL", "INFO")
38+
self.max_tasks_before_restart = os.environ.get("MAX_TASKS_BEFORE_RESTART", 0)

src/omotes_sdk/internal/worker/worker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ def start(self) -> None:
344344
# app.conf.worker_send_task_events = True # Tell the worker to send task events.
345345
self.celery_app.conf.worker_hijack_root_logger = False
346346
self.celery_app.conf.worker_redirect_stdouts = False
347+
# optionally restart celery worker after set number of tasks (runs)
348+
if self.config.max_tasks_before_restart != 0:
349+
self.celery_app.conf.worker_max_tasks_per_child = self.config.max_tasks_before_restart
347350

348351
logger.info(
349352
"Connected to broker rabbitmq (%s:%s/%s) as %s",

0 commit comments

Comments
 (0)