Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Workflow cancellation should cancel handler executions #575

Open
dandavison opened this issue Jul 9, 2024 · 0 comments · May be fixed by #653
Open

[Feature Request] Workflow cancellation should cancel handler executions #575

dandavison opened this issue Jul 9, 2024 · 0 comments · May be fixed by #653
Labels
enhancement New feature or request

Comments

@dandavison
Copy link
Contributor

dandavison commented Jul 9, 2024

Currently, workflow cancellation does not result in cancellation of in-progress signal/update handler executions.

For example, consider the case of update and see the sample below: the client waiting on the update gets an exception, but the exception is workflow execution already completed. This ticket calls for that exception to inform the client that the update was canceled due to cancellation of the workflow.

Doing this for signal handlers would be backwards-incompatible and hence will need to use an SDK workflow logic flag.

@workflow.defn
class UpdateCancellationWorkflow:
    def __init__(self) -> None:
        self.non_terminating_operation_has_started = False

    @workflow.run
    async def run(self) -> str:
        await workflow.wait_condition(lambda: False)
        return "unreachable"

    @workflow.update
    async def wait_until_non_terminating_operation_has_started(self) -> None:
        await workflow.wait_condition(
            lambda: self.non_terminating_operation_has_started
        )

    @workflow.update
    async def non_terminating_operation(self) -> str:
        self.non_terminating_operation_has_started = True
        await workflow.wait_condition(lambda: False)
        return "unreachable"


async def test_update_cancellation(client: Client):
    async with new_worker(client, UpdateCancellationWorkflow) as worker:
        wf_handle = await client.start_workflow(
            UpdateCancellationWorkflow.run,
            id=str(uuid.uuid4()),
            task_queue=worker.task_queue,
        )
        # Asynchronously run an update that will never complete
        non_terminating_update_task = asyncio.create_task(
            wf_handle.execute_update(
                UpdateCancellationWorkflow.non_terminating_operation
            )
        )
        print("wait until handler started...")
        # Wait until we know the update handler has started executing
        await wf_handle.execute_update(
            UpdateCancellationWorkflow.wait_until_non_terminating_operation_has_started
        )
        print("cancel the workflow")
        await wf_handle.cancel()
        print("await non_terminating_update_task...")
        await non_terminating_update_task
@dandavison dandavison added the enhancement New feature or request label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant