Skip to content

Commit

Permalink
FEA: Add cancel method to Service and Child
Browse files Browse the repository at this point in the history
  • Loading branch information
cortadocodes committed Feb 5, 2025
1 parent a4e7e0e commit f4c1c2b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions octue/cloud/pub_sub/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions octue/resources/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit f4c1c2b

Please sign in to comment.