Fix issue causing queue length query to hang

This commit is contained in:
Basraah 2018-01-08 18:20:29 +10:00
parent 6baab1d006
commit f97c8f2ce4
2 changed files with 5 additions and 0 deletions

View File

@ -0,0 +1 @@
from .celery import app as celery_app

View File

@ -1,5 +1,6 @@
import requests import requests
import logging import logging
import amqp.exceptions
import semantic_version as semver import semantic_version as semver
from django import template from django import template
from django.conf import settings from django.conf import settings
@ -54,6 +55,9 @@ def get_celery_queue_length():
with app.connection_or_acquire() as conn: with app.connection_or_acquire() as conn:
return conn.default_channel.queue_declare( return conn.default_channel.queue_declare(
queue=getattr(settings, 'CELERY_DEFAULT_QUEUE', 'celery'), passive=True).message_count queue=getattr(settings, 'CELERY_DEFAULT_QUEUE', 'celery'), passive=True).message_count
except amqp.exceptions.ChannelError:
# Queue doesn't exist, probably empty
return 0
except Exception: except Exception:
logger.exception("Failed to get celery queue length") logger.exception("Failed to get celery queue length")
return -1 return -1