Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/celery_backend/config.py
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | def get_queue_stats(self, queue_name): | ||||
url = 'http://{hostname}:{port}/api/queues/{vhost}/{queue}'.format( | url = 'http://{hostname}:{port}/api/queues/{vhost}/{queue}'.format( | ||||
hostname=conn_info['hostname'], | hostname=conn_info['hostname'], | ||||
port=conn_info['port'] + 10000, | port=conn_info['port'] + 10000, | ||||
vhost=urllib.parse.quote(conn_info['virtual_host'], safe=''), | vhost=urllib.parse.quote(conn_info['virtual_host'], safe=''), | ||||
queue=urllib.parse.quote(queue_name, safe=''), | queue=urllib.parse.quote(queue_name, safe=''), | ||||
) | ) | ||||
credentials = (conn_info['userid'], conn_info['password']) | credentials = (conn_info['userid'], conn_info['password']) | ||||
r = requests.get(url, auth=credentials) | r = requests.get(url, auth=credentials) | ||||
if r.status_code == 404: | |||||
vlorentz: When does this happen?
This should probably be merged with the behavior in `if conn_info… | |||||
Done Inline ActionsThis happens when the queue doesn't exist in RabbitMQ. What do you mean by "merged"? olasd: This happens when the queue doesn't exist in RabbitMQ.
What do you mean by "merged"? | |||||
return {} | |||||
if r.status_code != 200: | if r.status_code != 200: | ||||
raise ValueError('Got error %s when reading queue stats: %s' % ( | raise ValueError('Got error %s when reading queue stats: %s' % ( | ||||
r.status_code, r.json())) | r.status_code, r.json())) | ||||
return r.json() | return r.json() | ||||
def get_queue_length(self, queue_name): | def get_queue_length(self, queue_name): | ||||
"""Shortcut to get a queue's length""" | """Shortcut to get a queue's length""" | ||||
stats = self.get_queue_stats(queue_name) | stats = self.get_queue_stats(queue_name) | ||||
if stats: | if stats: | ||||
return stats['messages'] | return stats.get('messages') | ||||
INSTANCE_NAME = os.environ.get(CONFIG_NAME_ENVVAR) | INSTANCE_NAME = os.environ.get(CONFIG_NAME_ENVVAR) | ||||
if INSTANCE_NAME: | if INSTANCE_NAME: | ||||
CONFIG_NAME = CONFIG_NAME_TEMPLATE % INSTANCE_NAME | CONFIG_NAME = CONFIG_NAME_TEMPLATE % INSTANCE_NAME | ||||
else: | else: | ||||
CONFIG_NAME = DEFAULT_CONFIG_NAME | CONFIG_NAME = DEFAULT_CONFIG_NAME | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
When does this happen?
This should probably be merged with the behavior in if conn_info['transport'] == 'memory':.