- Install with npm ci from package-lock.json so a rebuild can't pull
different dependency versions than were tested.
- Run node directly (not via npm) so it receives SIGTERM and can drain
queued webhooks; give the stack a 60s stop_grace_period and start the
new task before stopping the old one.
- Add .dockerignore and stop tracking dist/ (already gitignored and
rebuilt by the Dockerfile).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Olist lookups: 20s timeout so one hung request can't stall the serial
queue; retry temporary failures (codigo_erro 6/11/35/99, timeouts,
5xx) with backoff instead of forwarding orders without phone or
forma_envio. Log "[Notification at risk]" when that still happens.
- n8n forwarding: timeout plus retries, only when n8n certainly didn't
run the workflow (connection refused, 502/503, 404 while restarting),
so retries can't send a customer the same WhatsApp twice. Stop logging
the start of N8N_AUTH_TOKEN.
- On SIGTERM, stop accepting requests and finish webhooks already acked
to Tiny (up to SHUTDOWN_GRACE_MS, default 50s).
- Keep stock_memory.json and stock_log.csv on the data-runtime volume so
stock stats survive redeploys.
- Add a node:test suite (npm test) covering the payload n8n reads, the
status cache, burst queueing, retries, stock files and shutdown drain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When more than ~5 webhooks arrived together, the 6s-spaced live Tiny
queue exceeded the 30s max wait and forwarded the order without Tiny
data: empty fone and forma_envio, so n8n silently sent no WhatsApp
message (19 such drops on 2026-10-08 alone).
Tiny is acked before the lookup, so waiting only adds latency. Raise the
default max queue wait to 15 minutes so it stays a last-resort valve
instead of something an ordinary burst can hit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tiny fires one webhook per status change, often under a minute apart
(e.g. "Preparando envio" -> "Pronto para envio"). The 120s order details
cache was keyed only by order ID, so the second webhook reused the first
fetch and forwarded the previous situacao to n8n, which then skipped the
message (notably the pickup "Pronto para envio" notification).
Key the cache and in-flight dedupe by order ID + webhook codigoSituacao,
so a status change always refetches while same-status duplicates still
share one Tiny call.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Refactor `sendToN8n` service to accept dynamic webhook URLs.
- Update `order-status` controller to fan-out payload to both STATUS and GRAPHS webhooks.
- Add new endpoints and controllers for stock and graphs updates (`/stock-update`, `/graphs-update`).
- Maintain backward compatibility with existing `N8N_WEBHOOK_URL` environment variable.