diff --git a/app.json b/app.json index 82e0ba41e..d7c60cb21 100644 --- a/app.json +++ b/app.json @@ -41,6 +41,7 @@ "PULSE_TASKS_QUEUE_NAME": { "generator": "secret" }, + "PULSE_AUTO_DELETE_QUEUES": true, "PROJECTS_TO_INGEST": { "value": "autoland,try" }, diff --git a/docker-compose.yml b/docker-compose.yml index cbf97a081..4a933aeee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: - UPSTREAM_DATABASE_URL=${UPSTREAM_DATABASE_URL:-} - PERF_SHERIFF_BOT_CLIENT_ID=${PERF_SHERIFF_BOT_CLIENT_ID:-} - PERF_SHERIFF_BOT_ACCESS_TOKEN=${PERF_SHERIFF_BOT_ACCESS_TOKEN:-} + - PULSE_AUTO_DELETE_QUEUES=True - REDIS_URL=redis://redis:6379 - SITE_URL=http://backend:8000/ - TREEHERDER_DEBUG=True diff --git a/treeherder/config/settings.py b/treeherder/config/settings.py index ce7935a1d..be93569eb 100644 --- a/treeherder/config/settings.py +++ b/treeherder/config/settings.py @@ -1,3 +1,4 @@ +import os import platform import re from datetime import timedelta @@ -34,6 +35,13 @@ GRAPHQL = env.bool("GRAPHQL", default=True) # Make this unique, and don't share it with anybody. SECRET_KEY = env("TREEHERDER_DJANGO_SECRET_KEY", default='secret-key-of-at-least-50-characters-to-pass-check-deploy') +# Delete the Pulse automatically when no consumers left +PULSE_AUTO_DELETE_QUEUES = env.bool("PULSE_AUTO_DELETE_QUEUES", default=False) + +# Changing PULSE_AUTO_DELETE_QUEUES to true when treeherder is running in virtual environment +if hasattr(os.environ, 'VIRTUAL_ENV'): + PULSE_AUTO_DELETE_QUEUES = True + # Hosts SITE_URL = env("SITE_URL", default='http://localhost:8000') diff --git a/treeherder/services/pulse/consumers.py b/treeherder/services/pulse/consumers.py index 22123d6c2..716c69d02 100644 --- a/treeherder/services/pulse/consumers.py +++ b/treeherder/services/pulse/consumers.py @@ -3,6 +3,7 @@ import threading import environ import newrelic.agent +from django.conf import settings from kombu import (Connection, Exchange, Queue) @@ -92,7 +93,7 @@ class PulseConsumer(ConsumerMixin): exchange=exchange, routing_key=routing_key, durable=True, - auto_delete=False, + auto_delete=settings.PULSE_AUTO_DELETE_QUEUES, ) self.consumers.append(dict(queues=self.queue, callbacks=[self.on_message]))