-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2169685
commit 984dd10
Showing
11 changed files
with
158 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: '3.0' | ||
|
||
services: | ||
redis: | ||
image: redis:7.4-alpine | ||
ports: | ||
- '6379:6379' | ||
command: redis-server --requirepass admin |
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,40 @@ | ||
import logging | ||
import logging.config | ||
|
||
from celery import Celery | ||
|
||
from ..plugin.parser import EntryPointPlugin | ||
|
||
|
||
def init_celery_manager(*, plugins: list[EntryPointPlugin]): | ||
""" | ||
Create a new Celery app and initialize it with the given plugins. | ||
""" | ||
from .. import manager | ||
|
||
_log = logging.getLogger(__name__) | ||
|
||
if not manager.settings.visyn_core.celery: | ||
_log.warning("No Celery settings found in configuration, skipping Celery initialization") | ||
return None | ||
|
||
manager.celery = Celery("visyn", **manager.settings.visyn_core.celery) | ||
|
||
# Discover tasks from all plugins, i.e. visyn_core.tasks, visyn_plugin.tasks | ||
manager.celery.autodiscover_tasks([p.id for p in plugins]) | ||
|
||
return manager.celery | ||
|
||
|
||
def create_celery_worker_app(*, workspace_config: dict | None = None): | ||
""" | ||
Create a new Celery app in standalone mode, i.e. without a FastAPI instance. | ||
""" | ||
from ..server.utils import init_settings_manager | ||
|
||
plugins = init_settings_manager(workspace_config=workspace_config) | ||
|
||
_log = logging.getLogger(__name__) | ||
_log.info("Starting celery worker") | ||
|
||
return init_celery_manager(plugins=plugins) |
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,11 @@ | ||
import logging | ||
import logging.config | ||
|
||
from visyn_core.celery.app import create_celery_worker_app | ||
|
||
from ..settings.constants import default_logging_dict | ||
|
||
# Initialize the logging very early as otherwise the already created loggers receive a default loglevel WARN, leading to logs not being shown. | ||
logging.config.dictConfig(default_logging_dict) | ||
|
||
celery_app = create_celery_worker_app() |
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
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,13 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from visyn_core import manager | ||
|
||
|
||
def test_celery_worker(client: TestClient): | ||
|
||
@manager.celery.task | ||
def add(x, y): | ||
return x + y | ||
|
||
result = add.delay(2, 4) | ||
assert result.get(timeout=1) == 6 |