Add "queue watched" indication for tasks.enqueue and tasks.enqueue_many

This commit is contained in:
allegroai 2022-11-29 17:36:41 +02:00
parent 6b3eff1426
commit bc23f1b0cf
3 changed files with 35 additions and 3 deletions

View File

@ -1948,6 +1948,17 @@ Fails if the following parameters in the task were not filled:
type: string type: string
} }
} }
"999.0": ${enqueue."2.19"} {
request.properties.verify_watched_queue {
description: If passed then check wheter there are any workers watiching the queue
type: boolean
default: false
}
response.properties.queue_watched {
description: Returns true if there are workers or autscalers working with the queue
type: boolean
}
}
} }
enqueue_many { enqueue_many {
"2.13": ${_definitions.change_many_request} { "2.13": ${_definitions.change_many_request} {
@ -1981,6 +1992,17 @@ enqueue_many {
type: string type: string
} }
} }
"999.0": ${enqueue_many."2.19"} {
request.properties.verify_watched_queue {
description: If passed then check wheter there are any workers watiching the queue
type: boolean
default: false
}
response.properties.queue_watched {
description: Returns true if there are workers or autscalers working with the queue
type: boolean
}
}
} }
dequeue { dequeue {
"1.5" { "1.5" {

View File

@ -850,6 +850,11 @@ def enqueue(call: APICall, company_id, request: EnqueueRequest):
queue_name=request.queue_name, queue_name=request.queue_name,
force=request.force, force=request.force,
) )
if request.verify_watched_queue:
res_queue = nested_get(res, ("fields", "execution.queue"))
if res_queue:
res["queue_watched"] = queue_bll.check_for_workers(company_id, res_queue)
call.result.data_model = EnqueueResponse(queued=queued, **res) call.result.data_model = EnqueueResponse(queued=queued, **res)
@ -871,12 +876,20 @@ def enqueue_many(call: APICall, company_id, request: EnqueueManyRequest):
), ),
ids=request.ids, ids=request.ids,
) )
extra = {}
if request.verify_watched_queue and results:
_id, (queued, res) = results[0]
res_queue = nested_get(res, ("fields", "execution.queue"))
if res_queue:
extra["queue_watched"] = queue_bll.check_for_workers(company_id, res_queue)
call.result.data_model = EnqueueManyResponse( call.result.data_model = EnqueueManyResponse(
succeeded=[ succeeded=[
EnqueueBatchItem(id=_id, queued=bool(queued), **res) EnqueueBatchItem(id=_id, queued=bool(queued), **res)
for _id, (queued, res) in results for _id, (queued, res) in results
], ],
failed=failures, failed=failures,
**extra,
) )

View File

@ -7,9 +7,6 @@ class TestBatchOperations(TestService):
comment = "this is a comment" comment = "this is a comment"
delete_params = dict(can_fail=True, force=True) delete_params = dict(can_fail=True, force=True)
def setUp(self, version="2.13"):
super().setUp(version=version)
def test_tasks(self): def test_tasks(self):
tasks = [self._temp_task() for _ in range(2)] tasks = [self._temp_task() for _ in range(2)]
models = [ models = [