|
|
|
|
@ -147,7 +147,7 @@ export const ResponseQueue = {
|
|
|
|
|
|
|
|
|
|
// Estadísticas de onboarding por destinatario (consulta simple sobre response_queue)
|
|
|
|
|
getOnboardingStats(recipient: string): { total: number; lastSentAt: string | null; firstInitialAt?: string | null; lastVariant?: 'initial' | 'reminder' | null } {
|
|
|
|
|
if (!recipient) return { total: 0, lastSentAt: null, firstInitialAt: undefined, lastVariant: null };
|
|
|
|
|
if (!recipient) return { total: 0, lastSentAt: null, lastVariant: null };
|
|
|
|
|
const rows = this.dbInstance.prepare(`
|
|
|
|
|
SELECT status, created_at, updated_at, metadata
|
|
|
|
|
FROM response_queue
|
|
|
|
|
@ -196,7 +196,11 @@ export const ResponseQueue = {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { total, lastSentAt, firstInitialAt, lastVariant };
|
|
|
|
|
const result: { total: number; lastSentAt: string | null; firstInitialAt?: string | null; lastVariant?: 'initial' | 'reminder' | null } = { total, lastSentAt, lastVariant };
|
|
|
|
|
if (typeof firstInitialAt !== 'undefined') {
|
|
|
|
|
result.firstInitialAt = firstInitialAt;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Encolar una reacción con idempotencia (24h) usando metadata canónica
|
|
|
|
|
@ -647,7 +651,7 @@ export const ResponseQueue = {
|
|
|
|
|
|
|
|
|
|
const interval = this.CLEANUP_INTERVAL_MS;
|
|
|
|
|
this._cleanupTimer = setInterval(() => {
|
|
|
|
|
this.runCleanupOnce().catch(err => console.error('Scheduled cleanup error:', err));
|
|
|
|
|
this.runCleanupOnce().catch((err: unknown) => console.error('Scheduled cleanup error:', err));
|
|
|
|
|
}, interval);
|
|
|
|
|
|
|
|
|
|
console.log(`🗓️ Cleanup scheduler started (every ${Math.round(interval / (60 * 60 * 1000))}h)`);
|
|
|
|
|
|