Skip to content

Use in-memory broker for dramatiq local development #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ services:
volumes:
- '.:/app'
depends_on:
- dramatiq-worker
- otel-collector
command:
- opentelemetry-instrument
Expand All @@ -34,7 +33,6 @@ services:
context: .
target: http_app
depends_on:
- dramatiq-worker
- otel-collector
env_file: local.env
environment:
Expand Down
3 changes: 2 additions & 1 deletion local.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ENVIRONMENT: "local"
AUTH__JWKS_URL: "http://oathkeeper:4456/.well-known/jwks.json"
DRAMATIQ__REDIS_URL: "redis://redis:6379/0"
#DRAMATIQ__REDIS_URL: "redis://redis:6379/0"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector:4317"
7 changes: 5 additions & 2 deletions src/common/dramatiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def init_dramatiq(config: AppConfig):
else:
broker = StubBroker()
# broker.emit_after("process_boot")
if config.ENVIRONMENT != "test":
logging.critical("Running a non-test environment without Redis URL set")
if config.ENVIRONMENT not in ["test", "local"]:
logging.critical(
"Running a non-test/non-local environment without Redis URL set",
extra={"ENVIRONMENT": config.ENVIRONMENT},
)
broker.add_middleware(AsyncIO())
set_broker(broker)
set_encoder(ORJSONEncoder())
4 changes: 3 additions & 1 deletion tests/common/test_dramatiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ def test_init_dramatiq_without_redis_url(caplog):
with caplog.at_level(logging.CRITICAL):
init_dramatiq(config)

assert "Running a non-test environment without Redis URL set" in caplog.text
assert (
"Running a non-test/non-local environment without Redis URL set" in caplog.text
)
Loading