Skip to content

Commit 22883c4

Browse files
ercpeJohann Schmitz
andauthored
Respect celery configuration namespace (#351)
When configuring Celery with RabbitMQ in Django, one often uses `app.config_from_object('django.conf:settings', namespace='CELERY')` as per the Celery Quick Start (https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html). This requires that all configuration keys in the Django settings have to be prefixed with `CELERY_`. The previous implementation only used `settings.BROKER_URL` (which may be `None`). When passing `None` to Celery (or more specifically: the `Connection` object), it would default to `localhost`. Expand the `RabbitMQHealthCheck` to accept a `namespace` attribute which can be set to `CELERY` for example. Co-authored-by: Johann Schmitz <johann.schmitz@dc1.com>
1 parent 4c5f866 commit 22883c4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

health_check/contrib/rabbitmq/backends.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
class RabbitMQHealthCheck(BaseHealthCheckBackend):
1414
"""Health check for RabbitMQ."""
1515

16+
namespace = None
17+
1618
def check_status(self):
1719
"""Check RabbitMQ service by opening and closing a broker channel."""
1820
logger.debug("Checking for a broker_url on django settings...")
1921

20-
broker_url = getattr(settings, "BROKER_URL", None)
22+
broker_url_setting_key = f"{self.namespace}_BROKER_URL" if self.namespace else "BROKER_URL"
23+
broker_url = getattr(settings, broker_url_setting_key, None)
2124

2225
logger.debug("Got %s as the broker_url. Connecting to rabbit...", broker_url)
2326

0 commit comments

Comments
 (0)