From e09a1d04e5b691c2762f438f6b2f37e5c6b80089 Mon Sep 17 00:00:00 2001 From: Markus Stahl Date: Mon, 13 Sep 2021 10:35:36 +0200 Subject: [PATCH] #7 init notify failure --- CamundaLibrary/CamundaLibrary.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/CamundaLibrary/CamundaLibrary.py b/CamundaLibrary/CamundaLibrary.py index 3598546..284f82e 100644 --- a/CamundaLibrary/CamundaLibrary.py +++ b/CamundaLibrary/CamundaLibrary.py @@ -20,7 +20,7 @@ VariableValueDto, FetchExternalTasksDto, FetchExternalTaskTopicDto, ProcessDefinitionApi, \ ProcessInstanceWithVariablesDto, StartProcessInstanceDto, ProcessInstanceModificationInstructionDto, \ ProcessInstanceApi, ProcessInstanceDto, VersionApi, EvaluateDecisionDto, MessageApi, \ - MessageCorrelationResultWithVariableDto, CorrelationMessageDto, ActivityInstanceDto + MessageCorrelationResultWithVariableDto, CorrelationMessageDto, ActivityInstanceDto, ExternalTaskFailureDto import generic_camunda_client as openapi_client @@ -415,6 +415,31 @@ def bpmn_error(self, error_code: str, error_message:str = None, variables: Dict[ except ApiException as e: logger.error(f"Exception when calling ExternalTaskApi->handle_external_task_bpmn_error: {e}\n") + @keyword("Notify failure", tags=["task", "beta"]) + def notify_failure(self, **kwargs): + """ + Raises a failure to Camunda. When retry counter is less than 1, an incident is created by Camunda. + + CamundaLibrary takes care of providing the worker_id and task_id. *retry_timeout* is equal to *lock_duration* for external tasks. + Check for camunda client documentation for all parameters of the request body: https://noordsestern.gitlab.io/camunda-client-for-python/7-15-0/docs/ExternalTaskApi.html#handle_failure + + Example: + | | ${variables} | *fetch workload* | _my_first_task_in_demo_ | | + | | *notify failure* | retries=3 | error_message= | _json=${{ {'workerId': '${fetch_response}[worker_id]'} }}_ | + """ + if not self.FETCH_RESPONSE: + logger.warn('No task to notify failure for. Maybe you did not fetch and lock a workitem before?') + else: + with self._shared_resources.api_client as api_client: + api_instance = openapi_client.ExternalTaskApi(api_client) + external_task_failure_dto = ExternalTaskFailureDto(worker_id=self.WORKER_ID, retry_timeout=60000, **kwargs) + + try: + api_instance.handle_failure(id=self.FETCH_RESPONSE.id, external_task_failure_dto=external_task_failure_dto) + self.drop_fetch_response() + except ApiException as e: + print("Exception when calling ExternalTaskApi->handle_failure: %s\n" % e) + @keyword("Complete task", tags=['task']) def complete(self, result_set: Dict[str, Any] = None, files: Dict = None): """