diff --git a/swh/scheduler/celery_backend/config.py b/swh/scheduler/celery_backend/config.py --- a/swh/scheduler/celery_backend/config.py +++ b/swh/scheduler/celery_backend/config.py @@ -98,7 +98,8 @@ Arguments: queue_name: name of the queue to check - Returns a dictionary raw from the RabbitMQ management API. + Returns a dictionary raw from the RabbitMQ management API; + or `None` if the current configuration does not use RabbitMQ. Interesting keys: - consumers (number of consumers for the queue) @@ -110,6 +111,9 @@ """ conn_info = self.connection().info() + if conn_info['transport'] == 'memory': + # We're running in a test environment, without RabbitMQ. + return None url = 'http://{hostname}:{port}/api/queues/{vhost}/{queue}'.format( hostname=conn_info['hostname'], port=conn_info['port'] + 10000, @@ -125,7 +129,9 @@ def get_queue_length(self, queue_name): """Shortcut to get a queue's length""" - return self.get_queue_stats(queue_name)['messages'] + stats = self.get_queue_stats(queue_name) + if stats: + return stats['messages'] INSTANCE_NAME = os.environ.get(CONFIG_NAME_ENVVAR) diff --git a/swh/scheduler/celery_backend/runner.py b/swh/scheduler/celery_backend/runner.py --- a/swh/scheduler/celery_backend/runner.py +++ b/swh/scheduler/celery_backend/runner.py @@ -50,8 +50,12 @@ if max_queue_length and backend_name in app.tasks: queue_name = app.tasks[backend_name].task_queue queue_length = app.get_queue_length(queue_name) - num_tasks = min(max_queue_length - queue_length, - MAX_NUM_TASKS) + if queue_length is None: + # Running without RabbitMQ (probably a test env). + num_tasks = MAX_NUM_TASKS + else: + num_tasks = min(max_queue_length - queue_length, + MAX_NUM_TASKS) else: num_tasks = MAX_NUM_TASKS if num_tasks > 0: