Skip to content

Commit

Permalink
refactor: moved import in datastore.py and eventboker.py into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
legout committed Aug 21, 2024
1 parent 9514a5f commit 21af0d0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[project]
authors = [{name = "Volker L.", email = "ligno.blades@gmail.com"}]
dependencies = [
"sf-hamilton[visualization]>=1.69.0",
"python-dotenv>=1.0.1",
"fsspec>=2024.5.0",
"pyyaml>=6.0.1",
"typer>=0.12.3",
"rich>=13.7.1",
"munch>=4.0.0",
"sf-hamilton-sdk>=0.5.2",
"sf-hamilton[visualization]>=1.69.0",
"python-dotenv>=1.0.1",
"fsspec>=2024.5.0",
"pyyaml>=6.0.1",
"typer>=0.12.3",
"rich>=13.7.1",
"munch>=4.0.0",
"sf-hamilton-sdk>=0.5.2",
"dill>=0.3.8",
]
description = "A simple workflow framework. Hamilton + APScheduler = FlowerPower"
keywords = [
Expand All @@ -23,7 +24,7 @@ keywords = [
name = "FlowerPower"
readme = "README.md"
requires-python = ">= 3.11"
version = "0.5.0"
version = "0.5.1"

[project.scripts]
flowerpower = "flowerpower.cli:app"
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ colorlog==6.8.2
decorator==5.1.1
# via ipython
dill==0.3.8
# via flowerpower
django==5.1
# via django-extensions
# via django-ninja
Expand Down
2 changes: 2 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ click==8.1.7
# via typer
colorlog==6.8.2
# via sf-hamilton-ui
dill==0.3.8
# via flowerpower
django==5.1
# via django-extensions
# via django-ninja
Expand Down
11 changes: 7 additions & 4 deletions src/flowerpower/helpers/datastore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore
from sqlalchemy.ext.asyncio import create_async_engine
from apscheduler.datastores.mongodb import MongoDBDataStore
from apscheduler.datastores.memory import MemoryDataStore


ALL_DATA_STORES = [
Expand All @@ -27,13 +23,20 @@ def __init__(self, type: str, engine_or_uri: str):
)

def _setup_sqlalchemy(self):
from apscheduler.datastores.sqlalchemy import SQLAlchemyDataStore
from sqlalchemy.ext.asyncio import create_async_engine

self.sqla_engine = create_async_engine(self.engine_or_uri)
self._data_store = SQLAlchemyDataStore(self.sqla_engine)

def _setup_mongodb(self, uri: str):
from apscheduler.datastores.mongodb import MongoDBDataStore

self._data_store = MongoDBDataStore(self.engine_or_uri)

def _setup_memory(self):
from apscheduler.datastores.memory import MemoryDataStore

self._data_store = MemoryDataStore()

def setup(
Expand Down
11 changes: 5 additions & 6 deletions src/flowerpower/helpers/eventbroker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

from apscheduler.eventbrokers.asyncpg import AsyncpgEventBroker
from apscheduler.eventbrokers.mqtt import MQTTEventBroker
from apscheduler.eventbrokers.redis import RedisEventBroker
from apscheduler.eventbrokers.local import LocalEventBroker
from sqlalchemy.engine import Engine

ALL_EVENT_BROKERS = [
Expand Down Expand Up @@ -42,6 +37,7 @@ def __init__(
)

def _setup_asyncpg_event_broker(self):
from apscheduler.eventbrokers.asyncpg import AsyncpgEventBroker

if self._sqla_engine is None:
self._event_broker = AsyncpgEventBroker.from_dsn(dsn=self.uri)
Expand All @@ -51,6 +47,7 @@ def _setup_asyncpg_event_broker(self):
)

def _setup_mqtt_event_broker(self):
from apscheduler.eventbrokers.mqtt import MQTTEventBroker

self._event_broker = MQTTEventBroker(
self.host, self.port, topic="flowerpower/scheduler"
Expand All @@ -62,12 +59,14 @@ def _setup_mqtt_event_broker(self):
)

def _setup_redis_event_broker(self):
from apscheduler.eventbrokers.redis import RedisEventBroker

if self.uri is None:
self.uri = f"redis://{self.host}:{self.port}"
self._event_broker = RedisEventBroker(self.uri)

def _setup_local_event_broker(self):
from apscheduler.eventbrokers.local import LocalEventBroker

self._event_broker = LocalEventBroker()

Expand Down Expand Up @@ -104,4 +103,4 @@ def setup_event_broker(
password=password,
)
eb.setup()
return eb.get()
return eb.get()

0 comments on commit 21af0d0

Please sign in to comment.