指南
Webhook
接收批次任務完成通知
對於超過一分鐘的批次任務,Webhook 比輪詢更便宜也更快。Thunderbit 會在任務進入終態時 POST 到你的 URL。
提交時設定
{
"urls": ["https://example.com/page1"],
"webhook": {
"url": "https://your-server.com/api/webhook/distill",
"secret": "whsec_your_secret_key",
"headers": { "X-Custom-Auth": "your-token" }
}
}Payload
{
"id": "batch_abc123",
"status": "COMPLETED",
"total": 50,
"completed": 49,
"failed": 1,
"completedAt": "2026-04-26T10:00:00Z"
}Payload 刻意精簡 —— 收到 callback 後再透過 GET /batch/distill/{id} 拉完整結果。
簽章驗證
當設定了 secret,每次投遞都會帶 X-Webhook-Signature: sha256=<hex>。用 HMAC-SHA256 驗證。
import hmac, hashlib
def verify(raw_body: bytes, signature: str, secret: str) -> bool:
expected = "sha256=" + hmac.new(
secret.encode(), raw_body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, signature)正式環境絕不要信任未簽章的 Webhook。
重試行為
- 非 2xx → 5 次重試,採指數退避:10s、30s、2m、10m、30m
- 單次投遞逾時:15s
- 所有重試都失敗後,任務在我們這邊仍視為完成 —— 你的端點必須是冪等的
本頁正在補充除錯訣竅 —— 敬請回訪。