Reiniciar U_Retry al reactivar, subscription:delete y fix de grupo huérfano
- Al reactivar una suscripción (resume o detección X -> A en el dispatcher) se reinicia U_Retry de sus entregas pendientes, para que no vuelva a 'X' en el siguiente tick. - Nuevo comando subscription:delete: borra filtros, entregas fallidas y eventos de @OEVN que quedan huérfanos. - Evita TypeError en sendPendingDeliveries cuando la suscripción pasa a 'X' después de armar su grupo de envío. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e1c8ee9015
commit
ec312d9461
3 files changed
+80
-3
No files matched your search
@@ -8,6 +8,7 @@
|
||||
// npx tsx scripts/manage-subscriptions.ts subscription:update-url <webhookId> <webhookUrl>
|
||||
// npx tsx scripts/manage-subscriptions.ts subscription:pause <webhookId>
|
||||
// npx tsx scripts/manage-subscriptions.ts subscription:resume <webhookId>
|
||||
// npx tsx scripts/manage-subscriptions.ts subscription:delete <webhookId>
|
||||
//
|
||||
// npx tsx scripts/manage-subscriptions.ts filter:add <webhookId> <bizObject> <transType> <objectType>
|
||||
// npx tsx scripts/manage-subscriptions.ts filter:remove <webhookId> <bizObject> <transType>
|
||||
@@ -15,6 +16,8 @@
|
||||
|
||||
import { config } from '../src/config.ts';
|
||||
import { ServiceLayerClient } from '../src/service-layer-client.ts';
|
||||
import * as evn1 from '../src/dispatcher/evn1-repository.ts';
|
||||
import * as oevn from '../src/dispatcher/oevn-repository.ts';
|
||||
import { generateCode } from '../src/lib/codes.ts';
|
||||
import { userTableEntity } from '../src/lib/service-layer-paths.ts';
|
||||
|
||||
@@ -87,7 +90,43 @@ async function main() {
|
||||
const [webhookId] = args;
|
||||
if (!webhookId) fail('subscription:resume <webhookId>');
|
||||
await client.patch(`/${OEVC}('${webhookId}')`, { U_State: 'A' });
|
||||
console.log(`Suscripción ${webhookId} reactivada (State='A').`);
|
||||
const reset = await evn1.resetRetries(client, webhookId);
|
||||
console.log(`Suscripción ${webhookId} reactivada (State='A'); ${reset} entrega(s) con U_Retry reiniciado a 0.`);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'subscription:delete': {
|
||||
const [webhookId] = args;
|
||||
if (!webhookId) fail('subscription:delete <webhookId>');
|
||||
|
||||
// 1) Entregas fallidas/pendientes (Status='F') de esta suscripción. Las ya
|
||||
// entregadas (Status='D') se conservan como historial.
|
||||
const failed = await evn1.listPendingForWebhook(client, webhookId);
|
||||
for (const row of failed) await evn1.deleteRow(client, row.code);
|
||||
|
||||
// 2) Eventos de @OEVN que quedaron sin ninguna entrega asociada (solo
|
||||
// existían para esta suscripción) se borran; los demás se recalculan.
|
||||
let eventsDeleted = 0;
|
||||
for (const eventId of new Set(failed.map((r) => r.eventId))) {
|
||||
const remaining = await evn1.listForEvent(client, eventId);
|
||||
if (remaining.length === 0) {
|
||||
await oevn.deleteEvent(client, eventId);
|
||||
eventsDeleted++;
|
||||
} else {
|
||||
await oevn.setEventStatus(client, eventId, remaining.every((r) => r.status === 'D') ? 'D' : 'P');
|
||||
}
|
||||
}
|
||||
|
||||
// 3) Filtros de @EVC1.
|
||||
const filters = await client.getAll(`/${EVC1}?$filter=${encodeURIComponent(`U_WebhookID eq '${webhookId}'`)}`);
|
||||
for (const f of filters) await client.delete(`/${EVC1}('${f.Code}')`);
|
||||
|
||||
// 4) La suscripción en sí.
|
||||
await client.delete(`/${OEVC}('${webhookId}')`);
|
||||
console.log(
|
||||
`Suscripción ${webhookId} eliminada: ${filters.length} filtro(s), ${failed.length} entrega(s) fallida(s), ` +
|
||||
`${eventsDeleted} evento(s) huérfano(s) de @OEVN.`,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -140,7 +179,7 @@ async function main() {
|
||||
default:
|
||||
fail(
|
||||
`comando desconocido: ${command ?? '(ninguno)'}\nComandos disponibles: subscription:add, subscription:list, ` +
|
||||
'subscription:update-url, subscription:pause, subscription:resume, filter:add, filter:remove, filter:list',
|
||||
'subscription:update-url, subscription:pause, subscription:resume, subscription:delete, filter:add, filter:remove, filter:list',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user