Repository navigation
Conversation
This script demonstrates how to deduplicate retried Cloud Scheduler HTTP requests using Firestore, ensuring that duplicate job requests are handled appropriately. Per b/574556578
Add unit tests for deduplicating job requests handling.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a Python snippet and corresponding unit tests demonstrating how to deduplicate retried Cloud Scheduler HTTP requests using Firestore. The feedback highlights a contradiction where manual runs (lacking the schedule time header) are rejected with a 400 error despite docstring claims, and suggests allowing them to run directly. Additionally, the reviewer recommends handling expired locks to prevent crashed jobs from blocking retries due to Firestore's asynchronous TTL deletion, along with adding unit tests to cover both scenarios.
Reordered import statements for consistency.
Added a link to the Cloud Scheduler documentation for deduplication.
|
Thanks @camiekim for this sample and for the docs page it supports. I've opened #14772 as a rewrite built on your work. You're credited as co-author, and it keeps the The main changes:
I also tested what the headers look like on each target type, which might be useful for the page:
If #14772 works for you, would you be open to closing this PR in favor of it? Feedback on the rewrite is very welcome. |
|
You are awesome, @iennae . I really appreciate you taking the time to rewrite the code properly. I will close this PR and pull in your new sample instead, and make the necessary updates in my CL (for example, state that the code uses a Firestore transaction with a lease to claim runs and recover from crashed attempts). Many thanks, again! |
…ob requests Add cloudscheduler_deduplicate_job_requests, a Cloud Run function that does a Cloud Scheduler job's work once per scheduled run, even when Cloud Scheduler delivers the same run more than once. The function identifies a run by the job name and the X-CloudScheduler-ScheduleTime header, which stays the same across retries. It claims the run in a Firestore transaction with a lease: - A completed run is skipped. - An active claim returns 409. - An expired claim from a crashed attempt can be claimed again. If the work fails, the function releases the claim so that Cloud Scheduler's retry can process the run. This rewrites the sample proposed in #14702 and keeps its region tag. Unit tests use an in-memory fake Firestore. Integration tests run against a real Firestore database and are skipped unless RUN_INTEGRATION_TESTS is set. Co-authored-by: Camie Kim <12733285+camiekim@users.noreply.github.com>
Description
Fixes b/574556578
Checklist
Testing
Compliance & Style
Post-Approval Actions