def reset(call: APICall, company_id, req_model: UpdateRequest): task = TaskBLL.get_task_with_access(req_model.task, company_id=company_id, requires_write_access=True) force = req_model.force if not force and task.status == TaskStatus.published: raise errors.bad_request.InvalidTaskStatus(task_id=task.id, status=task.status) api_results = {} updates = {} try: dequeued = _dequeue(task, company_id, silent_fail=True) except APIError: # dequeue may fail if the task was not enqueued pass else: if dequeued: api_results.update(dequeued=dequeued) updates.update(unset__execution__queue=1) cleaned_up = cleanup_task(task, force) api_results.update(attr.asdict(cleaned_up)) updates.update( set__last_iteration=DEFAULT_LAST_ITERATION, set__last_metrics={}, unset__output__result=1, unset__output__model=1, __raw__={"$pull": { "execution.artifacts": { "mode": { "$ne": "input" } } }}, ) res = ResetResponse(**ChangeStatusRequest( task=task, new_status=TaskStatus.created, force=force, status_reason="reset", status_message="reset", ).execute(started=None, completed=None, published=None, **updates)) for key, value in api_results.items(): setattr(res, key, value) call.result.data_model = res
def reset(call: APICall, company_id, req_model: UpdateRequest): task = TaskBLL.get_task_with_access(req_model.task, company_id=company_id, requires_write_access=True) force = req_model.force if not force and task.status == TaskStatus.published: raise errors.bad_request.InvalidTaskStatus(task_id=task.id, status=task.status) api_results = {} updates = {} cleaned_up = cleanup_task(task, force) api_results.update(attr.asdict(cleaned_up)) updates.update( unset__script__requirements=1, set__last_iteration=DEFAULT_LAST_ITERATION, set__last_metrics={}, unset__output__result=1, unset__output__model=1, ) res = ResetResponse(**ChangeStatusRequest( task=task, new_status=TaskStatus.created, force=force, status_reason="reset", status_message="reset", ).execute(started=None, completed=None, published=None, **updates)) for key, value in api_results.items(): setattr(res, key, value) call.result.data_model = res