aboutsummaryrefslogtreecommitdiffstats
path: root/gunicorn_config.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-06-06 19:12:03 +0100
committerGravatar Gareth Coles <[email protected]>2018-06-06 19:12:03 +0100
commitaa8680a7e662aebb335e1ac9f1e971251ecc04ea (patch)
treea310d9d286f66a87f9e4964038fcba7c5cdc630a /gunicorn_config.py
parent[CI] Documentation is a fine thing (diff)
RabbitMQ service discovery
Diffstat (limited to 'gunicorn_config.py')
-rw-r--r--gunicorn_config.py56
1 files changed, 32 insertions, 24 deletions
diff --git a/gunicorn_config.py b/gunicorn_config.py
index 7c86851e..4814f5bf 100644
--- a/gunicorn_config.py
+++ b/gunicorn_config.py
@@ -8,6 +8,7 @@ from pysite.constants import (
)
from pysite.migrations.runner import run_migrations
from pysite.queues import QUEUES
+from pysite.service_discovery import wait_for_rmq
STRIP_REGEX = re.compile(r"<[^<]+?>")
WIKI_TABLE = "wiki"
@@ -42,27 +43,34 @@ def _when_ready(server=None, output_func=None):
run_migrations(db, output=output)
- output("Declaring RabbitMQ queues...")
-
- try:
- with Connection(hostname=RMQ_HOST, userid=RMQ_USERNAME, password=RMQ_PASSWORD, port=RMQ_PORT) as c:
- with c.channel() as channel:
- for name, queue in QUEUES.items():
- queue.declare(channel=channel)
- output(f"Queue declared: {name}")
-
- if not DEBUG_MODE:
- producer = c.Producer()
- producer.publish(
- {
- "event": BotEventTypes.send_embed.value,
- "data": {
- "target": CHANNEL_DEV_LOGS,
- "title": "Site Deployment",
- "description": "The site has been deployed!"
- }
- },
- routing_key=BOT_EVENT_QUEUE
- )
- except Exception as e:
- output(f"Failed to declare RabbitMQ Queues: {e}")
+ output("Waiting for RabbitMQ...")
+
+ has_rmq = wait_for_rmq()
+
+ if not has_rmq:
+ output("Timed out while waiting for RabbitMQ")
+ else:
+ output("RabbitMQ found, declaring RabbitMQ queues...")
+
+ try:
+ with Connection(hostname=RMQ_HOST, userid=RMQ_USERNAME, password=RMQ_PASSWORD, port=RMQ_PORT) as c:
+ with c.channel() as channel:
+ for name, queue in QUEUES.items():
+ queue.declare(channel=channel)
+ output(f"Queue declared: {name}")
+
+ if not DEBUG_MODE:
+ producer = c.Producer()
+ producer.publish(
+ {
+ "event": BotEventTypes.send_embed.value,
+ "data": {
+ "target": CHANNEL_DEV_LOGS,
+ "title": "Site Deployment",
+ "description": "The site has been deployed!"
+ }
+ },
+ routing_key=BOT_EVENT_QUEUE
+ )
+ except Exception as e:
+ output(f"Failed to declare RabbitMQ Queues: {e}")