Skip to content

feat(workflows): Add client library sample to cancel an active execution - #14805

Open
iennae wants to merge 1 commit into
refactor/workflows-cloud-client-packagefrom
feat/workflows-cancel-execution
Open

iennae wants to merge 1 commit into
refactor/workflows-cloud-client-packagefrom
feat/workflows-cancel-execution

Conversation

@iennae

@iennae iennae commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Description

Adds cancel_execution.py (workflows_cancel_execution) using executions_v1.ExecutionsClient.cancel_execution to terminate an in-flight execution, verified by unit tests and a gated live integration test against a sleeping workflow.

Note: Stacked on #14797 (refactor/workflows-cloud-client-package) so this PR shows only this sample's diff.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit and live integration tests pass on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

@iennae
iennae requested review from a team as code owners November 14, 2026 00:22
@snippet-bot

snippet-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added api: workflows Issues related to the Workflows API. samples Issues that are directly related to samples. labels Nov 14, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new sample script and corresponding tests for cancelling a running Google Cloud Workflows execution. The feedback suggests utilizing the client library's built-in helper methods (execution_path and workflow_path) to construct resource paths instead of manually formatting them with f-strings, which improves robustness and aligns with best practices.

Comment on lines +34 to +37
name = (
f"projects/{project_id}/locations/{location_id}/workflows/{workflow_id}"
f"/executions/{execution_id}"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the client's built-in execution_path helper method instead of manually constructing the resource path with f-strings. This is more robust, less prone to formatting errors, and aligns with Google Cloud client library best practices.

    name = client.execution_path(project_id, location_id, workflow_id, execution_id)

Comment on lines +92 to +95
parent = (
f"projects/{conftest.LIVE_PROJECT_ID}/locations/{conftest.LIVE_LOCATION_ID}"
f"/workflows/{sleep_workflow_id}"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the client's built-in workflow_path helper method instead of manually constructing the parent resource path with f-strings. This is more robust and consistent with the rest of the codebase.

Suggested change
parent = (
f"projects/{conftest.LIVE_PROJECT_ID}/locations/{conftest.LIVE_LOCATION_ID}"
f"/workflows/{sleep_workflow_id}"
)
parent = executions_client.workflow_path(
conftest.LIVE_PROJECT_ID,
conftest.LIVE_LOCATION_ID,
sleep_workflow_id,
)

Stopping a stuck or superseded workflow run from Python lacked a sample showing `executions_v1` cancellation and state verification. Adding `workflows_cancel_execution` covers `cancel_execution` and `NotFound` handling on active runs.
@iennae
iennae force-pushed the feat/workflows-cancel-execution branch from a431a65 to 122bf44 Compare November 14, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: workflows Issues related to the Workflows API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant