Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

The Sweeper Pattern: How I Reconcile Crashed n8n Jobs Without Guessing

说明与用途

Sweeper 模式通过扫描过期租约并验证外部提供商的结果,自动恢复 n8n 崩溃的作业,避免重复操作。

问题

Crashed n8n jobs leave rows in an ambiguous "claimed" state, making it unclear whether the external action (email, charge, webhook) succeeded.

结果

Implemented a sweeper that reliably reconciles ambiguous job states, reducing duplicate external actions and providing a clear "review" state for human inspection.

工作流

  • Create jobs table with lease_seconds default 600
  • Worker atomically claims a queued job by updating state to "claimed" and setting claimed_at
  • Sweeper runs on schedule, selecting jobs where state is "claimed" and claimed_at is older than lease_seconds
  • For each expired job, determine provider class and available handle
  • If forced-unique provider with idempotency key or provider reference, re-drive or query provider to confirm success and set state to "done"
  • If suggestion-key provider with deterministic handle, look up provider; if found set to "done", if not found after settle window set to "review"
  • If suggestion-key provider with no handle, set to "review"
  • Ensure single-flight by using a sweep_locks table or atomic claim on sweeper rows
  • Handle kill scenarios by asserting provider-side counts and avoiding duplicate effects

证据

A sweeper is a scheduled job that scans for work left in an ambiguous state and decides its fate.

来源

Workers claim atomically — only the worker that gets the row proceeds:

来源

And the sweeper touches only expired leases:

来源

The lease is the line between "the worker is slow" and "the worker is dead." Ten minutes is my default.

来源

  • 记录日期: 2026-10-11T19:10:52.359Z