Repository navigation
Conversation
|
Here is the summary of changes. You are about to add 16 region tags.
You are about to delete 6 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request adds comprehensive Python samples and integration tests for Google Cloud Workflows, covering execution management, workflow lifecycles, scheduled run deduplication, idempotent payment processing, and saga patterns. The review feedback recommends adjusting the noxfile_config.py files across the new samples to test only the oldest (3.8) and newest (3.13) supported Python versions. Additionally, it suggests adding robust error handling when parsing JSON execution arguments in the scheduled runs integration tests to prevent unexpected test failures.
| return [ | ||
| execution | ||
| for execution in client.list_executions(request=request) | ||
| if json.loads(execution.argument or "{}").get("job_name") == job_id | ||
| ] |
There was a problem hiding this comment.
Parsing execution.argument directly with json.loads without error handling can cause the integration tests to fail if there are any executions with non-JSON arguments or if the parsed JSON is not a dictionary (which would raise an AttributeError on .get()). It is safer to handle json.JSONDecodeError and verify that the parsed argument is a dictionary.
| return [ | |
| execution | |
| for execution in client.list_executions(request=request) | |
| if json.loads(execution.argument or "{}").get("job_name") == job_id | |
| ] | |
| executions = [] | |
| for execution in client.list_executions(request=request): | |
| try: | |
| args = json.loads(execution.argument or "{}") | |
| if isinstance(args, dict) and args.get("job_name") == job_id: | |
| executions.append(execution) | |
| except json.JSONDecodeError: | |
| pass | |
| return executions |
The Workflows Python samples only ran executions: they covered 2 of the
10 client methods, defined one region tag in two files, used TODO
placeholders, and pinned an old library version. The new idempotency
tutorial also needs a Python sample that's safe to retry.
Client-library samples (workflows/cloud-client), using
google-cloud-workflows 1.24.0:
- Updated: workflows_execute_without_arguments,
workflows_execute_with_arguments, workflows_api_quickstart (main.py,
matching the Node.js tab; the duplicate tag and unused sub-tags are
removed). File paths are unchanged, because docs embed them by path.
- New:
- workflows_client_library (list workflows, matching Node.js and C++)
- workflows_create_workflow
- workflows_get_workflow
- workflows_update_workflow
- workflows_delete_workflow
- workflows_get_execution
- workflows_list_executions (uses the FULL view, which includes errors)
- workflows_cancel_execution
Idempotency samples, each a Cloud Run function backed by Firestore:
- idempotent_payment: workflows_idempotent_process_payment and
workflows_idempotent_order_workflow, for the "Make API calls
idempotent" tutorial.
- The function claims an order with a lease and an attempt ID, then
charges outside the transaction with the order ID as an idempotency
key.
- Orders have explicit states.
- On a duplicate request, the workflow resumes from the stored state
instead of exiting.
- deduplicate_scheduled_runs: workflows_deduplicate_scheduled_runs
starts a workflow once per Cloud Scheduler run. It keys on the
scheduled minute, because a forced run can send the schedule time
without Cloud Scheduler's per-job offset.
- order_saga: workflows_order_saga_workflow and
workflows_order_saga_refund refund a charge once when fulfillment
fails.
Tests live in tests/ subdirectories:
- Unit tests run without credentials.
- Integration tests are skipped unless RUN_INTEGRATION_TESTS is set.
They cover:
- duplicate and concurrent executions
- partial failures
- ambiguous failures and timeouts at two tiers
- crashed attempts
- Cloud Scheduler duplicate deliveries
- saga compensation
Each one checks that a stand-in payment service charged exactly once.
Unit and integration tests pass on Python 3.13.
4735ec4 to
191cb3a
Compare
Description
Modernizes the Cloud Workflows Python samples and adds idempotency samples. The idempotency samples support the in-progress Workflows tutorial "Make API calls idempotent" and the "Understand idempotency" concept page. The idempotent payment sample builds on the inline code in the tutorial draft by @camiekim.
Client-library samples (
workflows/cloud-client,google-cloud-workflows1.24.0)workflows_api_quickstartworkflows_execute_without_argumentstag and two unused sub-tags are removed)workflows_execute_without_argumentsworkflows_execute_with_argumentsworkflows_client_libraryworkflows_create_workflowworkflows_get_workflowworkflows_update_workflowworkflows_delete_workflowworkflows_get_executionworkflows_list_executionsworkflows_cancel_executionIdempotency samples (Cloud Run functions backed by Firestore)
idempotent_payment/workflows_idempotent_process_payment,workflows_idempotent_order_workflowdeduplicate_scheduled_runs/workflows_deduplicate_scheduled_runsorder_saga/workflows_order_saga_workflow,workflows_order_saga_refundWhat live testing found, compared with the tutorial's original code
http.default_retrywait for that attempt. 409 isn't retried.list_executionsneedsview=FULLto return execution errors.Tests (in
tests/subdirectories)RUN_INTEGRATION_TESTS=true. The idempotency tests inject faults, and each one checks that a stand-in payment service charged exactly once. They cover:Checklist
Testing
Compliance & Style
workflows, which the default owners cover.Post-Approval Actions