diff --git a/octue/cloud/pub_sub/service.py b/octue/cloud/pub_sub/service.py index 30408c5ef..2433df085 100644 --- a/octue/cloud/pub_sub/service.py +++ b/octue/cloud/pub_sub/service.py @@ -451,6 +451,31 @@ def wait_for_answer( finally: subscription.delete() + def cancel( + self, + question_uuid, + parent_question_uuid, + originator_question_uuid, + parent, + originator, + retry_count, + timeout=30, + ): + self._emit_event( + {"kind": "cancellation"}, + question_uuid=question_uuid, + parent_question_uuid=parent_question_uuid, + originator_question_uuid=originator_question_uuid, + parent=parent, + originator=originator, + recipient=parent, + retry_count=retry_count, + attributes={"sender_type": PARENT_SENDER_TYPE}, + timeout=timeout, + ) + + logger.info("%r requested cancellation of question %r.", self, question_uuid) + def send_exception( self, question_uuid, diff --git a/octue/resources/child.py b/octue/resources/child.py index 5ae6e9dc2..707292cd2 100644 --- a/octue/resources/child.py +++ b/octue/resources/child.py @@ -236,3 +236,23 @@ def ask_multiple( # Convert dictionary to list in asking order. return [answer[1] for answer in sorted(answers.items(), key=lambda item: item[0])] + + def cancel( + self, + question_uuid, + parent_question_uuid, + originator_question_uuid, + parent, + originator, + retry_count, + timeout=30, + ): + self._service.cancel( + question_uuid, + parent_question_uuid, + originator_question_uuid, + parent, + originator, + retry_count, + timeout=timeout, + )