Safely retry failed scheduled publishing attempts.
Quick solution:
if (locked) return;
await env.KV.put(k, v);
Why a Completed Workflow Does Not Prove Publication
A workflow run ending without an uncaught exception only proves that the orchestration completed. It does not prove that an external content API accepted the payload or that the downstream storage returned a valid identifier. If a network timeout occurs right after the remote server receives the request, the final step may fail or report ambiguous status. Treating workflow completion as absolute publication proof risks duplicate runs when an automated timer fires again.
Preventing Overlapping Retries with a Shared Writer Slot
Uncoordinated cron schedules and long-running retries can trigger multiple publishing instances concurrently. Using a shared key-value lock or single writer slot prevents this race condition. When a cron trigger fires according to documentation on Cloudflare Cron Triggers, it checks for an existing lock. If the slot is occupied, the current tick exits immediately rather than starting a parallel mutation.
Cooling Down Blocked Inputs Without Deletion
When a source draft or external provider fails validation, deleting it risks losing valuable work, while immediate retries waste compute budget. Instead, apply a cooldown timestamp to the item. This moves it out of the active selection pool for subsequent idle ticks. You can learn more about managing step pauses and recovery windows in the documentation on Cloudflare Workflows sleeping and retrying.
Defining Valid Success Evidence and Streak Tracking
A trial requires consecutive successful publications to pass. A success must be backed by a distinct production URL and a confirmed vault lifecycle entry. If an attempt produces an error or an incomplete response, the consecutive streak resets to zero, preventing partial outputs from accumulating false credit toward a 3/3 success threshold.
Bounding Attempts with Trial Expiry and Provider Distinctions
Transient provider unavailability differs fundamentally from permanent editorial rejections. Provider errors warrant exponential backoff within a finite window, whereas content rejections require human intervention. Bounding the entire trial with a fixed 24-hour expiry prevents deadlocked drafts from consuming background worker resources indefinitely.
Verification Checklist
- Confirm that a failed publishing attempt resets the consecutive success streak to zero in the ledger.
- Verify that an occupied writer slot successfully blocks overlapping cron ticks from executing.
- Check that a failed source input receives a cooldown timestamp and is skipped by the next idle tick.
- Ensure that trial expiration halts further automated retries after the 24-hour window closes.
Top comments (0)