Skip to content

Commit 7724a79

Browse files
committed
Init dramatiq on application start
Signed-off-by: Federico Busetti <[email protected]>
1 parent d2c807f commit 7724a79

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/common/bootstrap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .celery import init_celery
99
from .config import AppConfig
1010
from .di_container import Container
11+
from .dramatiq import init_dramatiq
1112
from .logs import init_logger
1213
from .storage import init_storage
1314

@@ -28,6 +29,7 @@ def application_init(app_config: AppConfig) -> InitReference:
2829
)
2930
init_logger(app_config)
3031
init_storage()
32+
init_dramatiq(app_config)
3133
celery = init_celery(app_config)
3234

3335
return InitReference(

src/common/dramatiq.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from dramatiq import set_broker
2+
from dramatiq.brokers.stub import StubBroker
3+
from dramatiq.middleware import AsyncIO
4+
from opentelemetry_instrumentor_dramatiq import DramatiqInstrumentor
5+
6+
from .config import AppConfig
7+
8+
9+
def init_dramatiq(config: AppConfig):
10+
DramatiqInstrumentor().instrument()
11+
if config.ENVIRONMENT == "test":
12+
broker = StubBroker()
13+
else:
14+
broker = StubBroker()
15+
# broker.emit_after("process_boot")
16+
broker.add_middleware(AsyncIO())
17+
set_broker(broker)

0 commit comments

Comments
 (0)