Dispatcher: evitar ticks solapados, enviar en lotes y mejorar logs
- index.ts: guard tickRunning; un tick largo ya no se solapa con el siguiente de node-cron (causaba -2035 en @EVN1 y -1116 cruzados por requests concurrentes sobre la misma sesion de Service Layer). - process-tick.ts: un evento con error ya no corta el tick; progreso cada 100 eventos; envios en lotes de MAX_EVENTS_PER_BATCH (default 30) para no superar el tamano de body del receptor (HTTP 413). - evn1-repository.ts: findExisting falla si el GET falla, en vez de tratarlo como "no existe" y crear un duplicado. - service-layer-client.ts: errores incluyen metodo, ruta y body. - logger.ts: no poder escribir el archivo de log no tumba el proceso. - CLAUDE.md: notas operativas y mejoras pendientes.
This commit is contained in:
1 parent
9e85c4cee8
commit
5a2e149825
8 files changed
+154
-45
No files matched your search
@@ -26,6 +26,10 @@ function toRow(raw: Record<string, unknown>): Evn1Row {
|
||||
export async function findExisting(client: ServiceLayerClient, eventId: string, webhookId: string): Promise<Evn1Row | null> {
|
||||
const filter = encodeURIComponent(`U_EventID eq '${eventId}' and U_WebhookID eq '${webhookId}'`);
|
||||
const res = await client.get(`/${ENTITY}?$filter=${filter}`);
|
||||
// Un GET fallido no es "no existe": tratarlo así lleva a un POST duplicado.
|
||||
if (res.status !== 200) {
|
||||
throw new Error(`Service Layer respondió HTTP ${res.status} buscando @EVN1 de ${eventId}: ${JSON.stringify(res.data)}`);
|
||||
}
|
||||
const rows = (res.data?.value as Record<string, unknown>[]) ?? [];
|
||||
return rows.length > 0 ? toRow(rows[0]) : null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user