Apps Script Error Handling: The Failed Invoice Your Ledger Skips Forever
说明与用途
在 Google Apps Script 发送发票时,静默错误导致发票被永久跳过,警报重复。通过添加区分失败与崩溃的账本、限制重试次数并去重警报,解决了此问题。
问题
Silent failures in Apps Script jobs cause invoices to be skipped permanently, leading to missed communications and duplicate alerts.
结果
The updated ledger logic prevents silent skips by distinguishing failures from crashes, limits retries to three attempts, and deduplicates alerts, reducing 124 alert emails during a weekend outage to a single notification.
工作流
- 1. Define ledger sheet with columns for key, state, attempts, and error.
- 2. Use processOnce to claim a key with a lock, marking it in_progress.
- 3. Execute the invoice send function inside a try/catch.
- 4. On success, mark the key as done; on error, mark as failed or gave_up based on MAX_ATTEMPTS.
- 5. Deduplicate alerts using alertOnce with a 3600‑second window.
- 6. Run watchdog hourly to monitor job health and send alerts only once per interval.
证据
One failed send becomes an invoice that is never sent.
A weekend outage sends 124 alert emails.
processOnce asks one question before it runs anything: is this key anywhere in column B?
- 记录日期: 2026-11-02T00:29:17.566Z