Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
]
description = "Python implementation of the OMOTES SDK through jobs which may be submitted, receive status updates for submitted jobs or delete submitted jobs."
readme = "README.md"
license = {file = "LICENSE"}
license = { file = "LICENSE" }
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
Expand All @@ -26,7 +26,7 @@ classifiers = [
dependencies = [
"aio-pika ~= 9.4, < 9.5",
"omotes-sdk-protocol ~= 1.2",
"pyesdl ~= 25.7",
"pyesdl ~= 26.2",
"pamqp ~= 3.3",
"celery ~= 5.3",
"typing-extensions ~= 4.11",
Expand Down
3 changes: 3 additions & 0 deletions src/omotes_sdk/internal/worker/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class WorkerConfig:
"""Name of the queue to which progress updates for the task should be send."""
log_level: str
"""Log level for any logging in the worker."""
max_tasks_before_restart: int
"""The number of tasks (runs) after which the celery worker will be restarted."""

def __init__(self) -> None:
"""Create the worker config and retrieve values from environment variables."""
Expand All @@ -33,3 +35,4 @@ def __init__(self) -> None:
"TASK_PROGRESS_QUEUE_NAME", "omotes_task_progress_events"
)
self.log_level = os.environ.get("LOG_LEVEL", "INFO")
self.max_tasks_before_restart = int(os.environ.get("MAX_TASKS_BEFORE_RESTART", 0))
3 changes: 3 additions & 0 deletions src/omotes_sdk/internal/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ def start(self) -> None:
# app.conf.worker_send_task_events = True # Tell the worker to send task events.
self.celery_app.conf.worker_hijack_root_logger = False
self.celery_app.conf.worker_redirect_stdouts = False
# optionally restart celery worker after set number of tasks (runs)
if self.config.max_tasks_before_restart != 0:
self.celery_app.conf.worker_max_tasks_per_child = self.config.max_tasks_before_restart

logger.info(
"Connected to broker rabbitmq (%s:%s/%s) as %s",
Expand Down
Loading