-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Celery as an executor and refactor threadng logic
- Implement Celery for task execution - Refactor code to improve thread handling and structure
- Loading branch information
Mohammad Torkashvand
committed
Nov 11, 2024
1 parent
64fb491
commit cb6aaff
Showing
13 changed files
with
146 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Environment configuration for LSO application | ||
|
||
# General settings | ||
LSO_ENV_PREFIX=LSO_ | ||
|
||
# Ansible configuration | ||
LSO_ANSIBLE_PLAYBOOKS_ROOT_DIR=/path/to/ansible/playbooks | ||
|
||
# Executor configuration | ||
LSO_EXECUTOR=threadpool # Options: "threadpool", "celery" | ||
LSO_MAX_THREAD_POOL_WORKERS=10 | ||
|
||
# Request settings | ||
LSO_DEFAULT_REQUEST_TIMEOUT_SEC=10 | ||
|
||
# Celery configuration | ||
LSO_CELERY_BROKER_URL=redis://localhost:6379/0 | ||
LSO_CELERY_RESULT_BACKEND=redis://localhost:6379/0 | ||
LSO_CELERY_TIMEZONE=Europe/Amsterdam | ||
LSO_CELERY_ENABLE_UTC=True | ||
LSO_CELERY_RESULT_EXPIRES=3600 | ||
|
||
# Debug/Testing | ||
LSO_TESTING=False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Module that sets up :term:`LSO` as a Celery worker.""" | ||
|
||
from celery import Celery | ||
from celery.signals import worker_shutting_down | ||
|
||
from lso.config import settings | ||
|
||
celery = Celery( | ||
"lso-worker", | ||
broker=settings.CELERY_BROKER_URL, | ||
backend=settings.CELERY_RESULT_BACKEND, | ||
include=[ | ||
"lso.schedules.task_vacuum", | ||
], | ||
) | ||
|
||
if settings.TESTING: | ||
celery.conf.update(backend=settings.CELERY_RESULT_BACKEND, task_ignore_result=False) | ||
else: | ||
celery.conf.update(task_ignore_result=True) | ||
|
||
celery.conf.update( | ||
result_expires=settings.CELERY_RESULT_EXPIRES, | ||
worker_prefetch_multiplier=1, | ||
worker_send_task_event=True, | ||
task_send_sent_event=True, | ||
redbeat_redis_url=settings.CELERY_BROKER_URL, | ||
) | ||
|
||
|
||
@worker_shutting_down.connect # type: ignore[misc] | ||
def worker_shutting_down_handler(sig, how, exitcode, **kwargs) -> None: # type: ignore[no-untyped-def] # noqa: ARG001 | ||
"""Handle the Celery worker shutdown event.""" | ||
celery.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.