Skip to content

Commit e5074f6

Browse files
committed
Use Redis broker for non-test environments
Signed-off-by: Federico Busetti <[email protected]>
1 parent d235417 commit e5074f6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/common/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
TYPE_ENVIRONMENT = Literal["local", "test", "staging", "production"]
99

1010

11+
class DramatiqConfig(BaseModel):
12+
REDIS_HOST: Optional[str] = None
13+
1114
class CeleryConfig(BaseModel):
1215
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#configuration
1316

@@ -47,6 +50,7 @@ class AppConfig(BaseSettings):
4750

4851
APP_NAME: str = "bootstrap"
4952
CELERY: CeleryConfig = CeleryConfig()
53+
DRAMATIQ: DramatiqConfig = DramatiqConfig()
5054
DEBUG: bool = False
5155
ENVIRONMENT: TYPE_ENVIRONMENT = "local"
5256
SQLALCHEMY_CONFIG: Dict[str, SQLAlchemyConfig] = dict(

src/common/dramatiq.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from dramatiq import set_broker
22
from dramatiq.brokers.stub import StubBroker
3+
from dramatiq.brokers.redis import RedisBroker
34
from dramatiq.middleware import AsyncIO
45
from opentelemetry_instrumentor_dramatiq import DramatiqInstrumentor
56

@@ -10,8 +11,10 @@ def init_dramatiq(config: AppConfig):
1011
DramatiqInstrumentor().instrument()
1112
if config.ENVIRONMENT == "test":
1213
broker = StubBroker()
14+
# broker.emit_after("process_boot")
15+
elif config.DRAMATIQ.REDIS_HOST is not None:
16+
broker = RedisBroker(host=config.DRAMATIQ.REDIS_HOST)
1317
else:
14-
broker = StubBroker()
15-
# broker.emit_after("process_boot")
18+
raise RuntimeError("Running a non-test environment without Redis host set")
1619
broker.add_middleware(AsyncIO())
1720
set_broker(broker)

0 commit comments

Comments
 (0)