File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 88TYPE_ENVIRONMENT = Literal ["local" , "test" , "staging" , "production" ]
99
1010
11+ class DramatiqConfig (BaseModel ):
12+ REDIS_HOST : Optional [str ] = None
13+
1114class 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 (
Original file line number Diff line number Diff line change 11from dramatiq import set_broker
22from dramatiq .brokers .stub import StubBroker
3+ from dramatiq .brokers .redis import RedisBroker
34from dramatiq .middleware import AsyncIO
45from 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 )
You can’t perform that action at this time.
0 commit comments