From e1992e2054bebd2890dec6280d27323915f6bf8e Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Tue, 15 Mar 2022 16:28:49 +0200 Subject: [PATCH] Fix queue metrics calculation --- apiserver/bll/queue/queue_bll.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apiserver/bll/queue/queue_bll.py b/apiserver/bll/queue/queue_bll.py index 456291a..a4b0c8b 100644 --- a/apiserver/bll/queue/queue_bll.py +++ b/apiserver/bll/queue/queue_bll.py @@ -187,13 +187,15 @@ class QueueBLL(object): if any(e.task == task_id for e in queue.entries): raise errors.bad_request.TaskAlreadyQueued(task=task_id) - self.metrics.log_queue_metrics_to_es(company_id=company_id, queues=[queue]) - entry = Entry(added=datetime.utcnow(), task=task_id) query = dict(id=queue_id, company=company_id) res = Queue.objects(entries__task__ne=task_id, **query).update_one( push__entries=entry, last_update=datetime.utcnow(), upsert=False ) + + queue.reload() + self.metrics.log_queue_metrics_to_es(company_id=company_id, queues=[queue]) + if not res: raise errors.bad_request.InvalidQueueOrTaskNotQueued( task=task_id, **query @@ -233,7 +235,6 @@ class QueueBLL(object): queue = self.get_queue_with_task( company_id=company_id, queue_id=queue_id, task_id=task_id ) - self.metrics.log_queue_metrics_to_es(company_id, queues=[queue]) entries_to_remove = [e for e in queue.entries if e.task == task_id] query = dict(id=queue_id, company=company_id) @@ -241,6 +242,9 @@ class QueueBLL(object): pull_all__entries=entries_to_remove, last_update=datetime.utcnow() ) + queue.reload() + self.metrics.log_queue_metrics_to_es(company_id=company_id, queues=[queue]) + return len(entries_to_remove) if res else 0 def reposition_task(