Skip to content

fix(frenet): Update order delivery status from Frenet tracking again - #866

Merged
leomp12 merged 4 commits into
mainfrom
fix/frenet-tracking-codes
Oct 27, 2026
Merged

leomp12 merged 4 commits into
mainfrom
fix/frenet-tracking-codes

Conversation

@leomp12

@leomp12 leomp12 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Problema

O rastreio automático da Frenet nunca funcionou no v2: getAll chamava data.toDate() sobre o documento inteiro (em vez de data.createdAt.toDate()), o erro estourava dentro do .then e a promise nunca resolvia. O cron horário ficava pendurado até o timeout, nenhum pedido era atualizado e a limpeza das 23h nunca rodava. Encontrado na review adversarial do #863.

Mudanças

  • Lê createdAt corretamente em getAll e getAllDelivered.
  • Só rastreia códigos dos últimos 60 dias (mesmo prazo da limpeza). Como a coleção nunca foi limpa, sem esse filtro a primeira execução atualizaria pedidos antigos e poderia disparar e-mails de "entregue" para clientes de 2023. Os códigos antigos são pulados e apagados pela limpeza diária, sem notificação.
  • Eventos da Frenet com mais de 7 dias geram fulfillment com customer_notified: true: o status do pedido é atualizado, mas o app de e-mails não notifica o cliente.
  • clear roda a cada execução (antes só às 23h) com BulkWriter, para esvaziar a coleção acumulada.
  • Erros do Firestore em remove, update, save e nas listagens agora propagam, em vez de deixar a promise pendurada.
  • Códigos processados de 10 em 10 e timeout do cron em 540s (antes 60s padrão, com concorrência ilimitada).
  • Status gravado como string em update (antes era número, e as consultas != '9' / == '9' nunca casavam com entregues). As consultas aceitam '9' e 9.
  • Timeout de 10s nas chamadas à Frenet; antes um erro HTTP deixava a promise pendurada para sempre.
  • removeDeliveredToFirestore espera as remoções e não loga erro quando não há códigos entregues.

Validação

tsc --noEmit, ESLint e build do pacote. Não houve teste em runtime contra o Firestore.

🤖 Generated with Claude Code

https://claude.ai/code/session_011YfvCxVikTh42WGmNu6chf

leomp12 and others added 4 commits October 26, 2026 20:16
Tracking codes were never read back from Firestore (`data.toDate()` on the
whole document threw), so the hourly cron hung until timeout and orders were
never updated by Frenet tracking. Delivered and old codes were never cleaned.

- Read `createdAt` from each tracking doc
- Only track codes from the last 60 days, so customers of old orders are not
  notified; older codes are removed by the daily cleanup, which now awaits
- Store tracking status as string so delivered codes match the queries
- Fail Frenet API calls after 10s instead of hanging on HTTP errors
- Await removal of delivered codes and stop logging an error when none exist

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011YfvCxVikTh42WGmNu6chf
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011YfvCxVikTh42WGmNu6chf
…ng runs

- Propagate Firestore errors in remove, update and code listing instead of
  leaving promises pending forever
- Process tracking codes 10 at a time and raise cron timeout to 540s
- Remove old codes on every run with BulkWriter, not only at 23h

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011YfvCxVikTh42WGmNu6chf
… week

Fulfillments from Frenet events older than 7 days are posted with
`customer_notified: true`, so the emails app skips them while the order
status and other apps still get the update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011YfvCxVikTh42WGmNu6chf
@leomp12
leomp12 merged commit 860b358 into main Oct 27, 2026
2 checks passed
@leomp12
leomp12 deleted the fix/frenet-tracking-codes branch October 27, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant