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

The Scheduled Workflow That Ran Twice: Overlapping Runs in n8n

说明与用途

在 n8n 中,计划的每小时工作流如果前一次运行仍在进行,可能会并发执行,导致数据重复。解决方案是在 PostgreSQL 中使用具有过期租约的原子锁,确保一次只执行一个运行,并记录被跳过的运行。

问题

A scheduled n8n workflow ran twice concurrently, causing duplicate updates and duplicate emails.

结果

The lock mechanism prevented overlapping runs, eliminated duplicate updates, and provided transparent alerts for skipped or reclaimed executions.

工作流

  • 1. Acquire lock atomically in Postgres; if locked, skip run with alert.
  • 2. If lock acquired, proceed with data pull, LLM enrichment, and write.
  • 3. Release lock at end only if token matches, in always‑run path.
  • 4. Log outcomes: acquired, already locked, stale lease reclaimed.

证据

The schedule is a clock, not a queue. It will happily start run N+1 while run N is still running.

来源

Acquiring the lock is a single atomic statement: update the row only if it is unlocked, or if its lease has expired.

来源

The release belongs in the workflow's always‑run path, the same place error handling lives, so a failed run frees the lock immediately and the next scheduled run can proceed on time.

来源

  • 记录日期: 2026-11-02T03:43:45.093Z