I have a use case where when a workflow is cancelled, I want to await the completion of one the child workflows before proceeding with the clean up logic.
Basically, this is part of a document processing workflow. If a user uploads a new copy of the document, we want to cancel the processing, but only after waiting for the malware scan on the document to come back clean. If the malware scan returns an alert, we lock down the document and don’t allow the user to upload a new copy.
So I have code that looks something like this
try:
malware_scan_promise = workflow.execute_child_workflow(
malare_scan.run,
MalwareArgs(
doc_id=doc_id
),
task_queue="task_queue",
parent_close_policy=ParentClosePolicy.ABANDON,
)
malware_result = await malware_scan_promise
except asyncio.CancelledError:
malware_result = await malware_scan_promise
if !malware_result:
# take special action
//cleanup activity
Does this make sense for what i am trying to accomplish ? Essentially, I want to kick off the child workflow asynchornously so that the cancellation is not passed down from the parent. But if the parent is cancelled, I still want to await the return value in the cancellation handler.