diff --git a/README.md b/README.md index 93c5922e..a71cb8d2 100644 --- a/README.md +++ b/README.md @@ -139,8 +139,14 @@ pip install -r requirements-dev.txt for development purposes, it's useful to run the example application: ```sh cd examples/ -export PYTHONPATH=$(pwd)/.. -uvicorn dummy.app:app --reload --reload-dir .. + +# Create a venv for the example app +python -m venv .venv +source .venv/bin/activate +pip install -r requirements + +./run.sh +# or ./run.ps1 on windows ``` The React frontend is in the `frontend/` folder, enter the folder diff --git a/examples/requirements.txt b/examples/requirements.txt new file mode 100644 index 00000000..33889f63 --- /dev/null +++ b/examples/requirements.txt @@ -0,0 +1,3 @@ +-e .. +python-dateutil +pandas \ No newline at end of file diff --git a/examples/run.ps1 b/examples/run.ps1 index 3132246c..5d492f92 100644 --- a/examples/run.ps1 +++ b/examples/run.ps1 @@ -1,2 +1,2 @@ -$env:PYTHONPATH="$(pwd)/.." +$env:PYTHONPATH="$(pwd)" python src/app.py \ No newline at end of file diff --git a/examples/run.sh b/examples/run.sh index 852087e7..c0db7aa9 100755 --- a/examples/run.sh +++ b/examples/run.sh @@ -1,2 +1,2 @@ -export PYTHONPATH=$(pwd)/.. +export PYTHONPATH=$(pwd) python src/app.py \ No newline at end of file diff --git a/examples/src/app.py b/examples/src/app.py index 930fdd45..1cdb7e3c 100644 --- a/examples/src/app.py +++ b/examples/src/app.py @@ -4,7 +4,7 @@ from plombery import get_app # noqa: F401 -from examples.src import sales_pipeline, sync_pipeline # noqa: F401 +from src import sales_pipeline, sync_pipeline # noqa: F401 if __name__ == "__main__": diff --git a/frontend/package.json b/frontend/package.json index b54ff492..fd3d68bb 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "plombery", - "version": "0.3.0-rc2", + "version": "0.3.0", "description": "", "license": "MIT", "author": { diff --git a/src/plombery/__init__.py b/src/plombery/__init__.py index 637af9b4..13407d8b 100644 --- a/src/plombery/__init__.py +++ b/src/plombery/__init__.py @@ -1,5 +1,6 @@ -import logging from typing import List, Type +import logging +import os from apscheduler.schedulers.base import SchedulerAlreadyRunningError from pydantic import BaseModel @@ -20,15 +21,15 @@ _logger.addHandler(logging.StreamHandler()) +if os.getenv("DEBUG_APS"): + logging.basicConfig() + logging.getLogger("apscheduler").setLevel(logging.DEBUG) + + class _Plombery: def __init__(self) -> None: self._apply_settings() - try: - orchestrator.start() - except SchedulerAlreadyRunningError: - pass - def _apply_settings(self): for notification in settings.notifications or []: self.add_notification_rule(notification) @@ -51,6 +52,14 @@ async def __call__(self, scope, receive, send): _app = _Plombery() +@app.on_event("startup") +def on_fastapi_start(): + try: + orchestrator.start() + except SchedulerAlreadyRunningError: + pass + + def get_app(): return _app diff --git a/src/plombery/_version.py b/src/plombery/_version.py index ce9c6638..cc1cea4c 100644 --- a/src/plombery/_version.py +++ b/src/plombery/_version.py @@ -1,3 +1,3 @@ # Keep it aligned with version in package.json -__version__ = "0.3.0-rc2" +__version__ = "0.3.0" diff --git a/src/plombery/orchestrator/__init__.py b/src/plombery/orchestrator/__init__.py index dba4b2c8..24d2dd8e 100644 --- a/src/plombery/orchestrator/__init__.py +++ b/src/plombery/orchestrator/__init__.py @@ -1,5 +1,5 @@ -from datetime import datetime, timedelta from typing import Any, Dict, Tuple +from datetime import datetime, timedelta from apscheduler.executors.asyncio import AsyncIOExecutor from apscheduler.job import Job @@ -37,6 +37,7 @@ def register_pipeline(self, pipeline: Pipeline): self.scheduler.add_job( id=job_id, + name=job_id, func=run, trigger=trigger.schedule, kwargs=dict(pipeline=pipeline, trigger=trigger),