-
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.
Merge branch 'develop' into dmoitzi/proms-and-vcf-icons-for-aevidence
- Loading branch information
Showing
14 changed files
with
163 additions
and
53 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
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,44 @@ | ||
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) | ||
|
||
_log.info("Initializing celery app") | ||
|
||
# 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 .. import manager | ||
from ..server.visyn_server import create_visyn_server | ||
|
||
# Create the whole FastAPI instance to ensure that the configuration and plugins are loaded, extension points are registered, database migrations are executed, ... | ||
create_visyn_server(workspace_config=workspace_config) | ||
|
||
_log = logging.getLogger(__name__) | ||
_log.info("Starting celery worker") | ||
|
||
return init_celery_manager(plugins=manager.registry.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,3 @@ | ||
from .app import create_celery_worker_app | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import os | ||
import pathlib | ||
import sys | ||
|
||
from .server.visyn_server import create_visyn_server | ||
|
||
# This app is either started via the uvicorn runner in __main__.py, | ||
# or as module to execute commands via `python -m <app>.dev_app db-migration exec ...` | ||
app = create_visyn_server( | ||
start_cmd=" ".join(sys.argv[1:]), workspace_config={"_env_file": os.path.join(os.path.dirname(os.path.realpath(__file__)), ".env")} | ||
) | ||
app = create_visyn_server(start_cmd=" ".join(sys.argv[1:]), workspace_config={"_env_file": pathlib.Path(__file__).parent / ".env"}) |
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,5 @@ | ||
import pathlib | ||
|
||
from .celery.app import create_celery_worker_app | ||
|
||
celery_app = create_celery_worker_app(workspace_config={"_env_file": pathlib.Path(__file__).parent / ".env"}) |
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 |