feat(sat-sync): expand incremental sync to all plans except Custom and Mi empresa

- Daily sync already covers all active tenants with FIEL (no plan filter)
- Incremental sync now runs for all plans EXCEPT:
  - 'custom'
  - 'mi_empresa'
  - 'mi_empresa_plus'
- Renamed getEnterpriseTenantsWithFiel -> getIncrementalTenantsWithFiel
- Updated logs to reflect new eligibility
This commit is contained in:
Horux Dev
2026-04-30 03:02:19 +00:00
parent 86c04159b0
commit 8e83dd2276

View File

@@ -122,16 +122,25 @@ async function runSyncJob(): Promise<void> {
}
/**
* Obtiene los tenants Enterprise activos con FIEL configurada.
* Planes excluidos del incremental (Custom y Mi empresa no reciben sync frecuente).
*/
async function getEnterpriseTenantsWithFiel(): Promise<string[]> {
const INCREMENTAL_EXCLUDED_PLANS = new Set(['custom', 'mi_empresa', 'mi_empresa_plus']);
/**
* Obtiene los tenants activos con FIEL configurada que son elegibles para sync incremental.
* Incluye todos los planes EXCEPTO Custom y Mi empresa / Mi empresa plus.
*/
async function getIncrementalTenantsWithFiel(): Promise<string[]> {
const tenants = await prisma.tenant.findMany({
where: { active: true, plan: 'enterprise' },
select: { id: true },
where: { active: true },
select: { id: true, plan: true },
});
const result: string[] = [];
for (const tenant of tenants) {
if (INCREMENTAL_EXCLUDED_PLANS.has(tenant.plan || '')) {
continue;
}
if (await hasFielConfigured(tenant.id)) {
result.push(tenant.id);
}
@@ -170,7 +179,8 @@ async function incrementalSyncTenant(tenantId: string): Promise<void> {
}
/**
* Ejecuta el job incremental de 6 horas para todos los tenants Enterprise.
* Ejecuta el job incremental de 6 horas para todos los tenants elegibles.
* Elegibles = todos los planes EXCEPTO Custom y Mi empresa.
*/
async function runIncrementalSyncJob(): Promise<void> {
if (isIncrementalRunning) {
@@ -179,11 +189,11 @@ async function runIncrementalSyncJob(): Promise<void> {
}
isIncrementalRunning = true;
console.log('[SAT Cron Inc] Iniciando ciclo incremental Enterprise');
console.log('[SAT Cron Inc] Iniciando ciclo incremental');
try {
const tenantIds = await getEnterpriseTenantsWithFiel();
console.log(`[SAT Cron Inc] ${tenantIds.length} tenants Enterprise con FIEL`);
const tenantIds = await getIncrementalTenantsWithFiel();
console.log(`[SAT Cron Inc] ${tenantIds.length} tenants elegibles con FIEL`);
if (tenantIds.length === 0) return;
@@ -480,7 +490,7 @@ export function startSatSyncJob(): void {
console.log(`[SAT Cron] Retry programado cada hora`);
console.log(`[Opinion Cron] Programado para: ${OPINION_CRON_SCHEDULE} (America/Mexico_City)`);
console.log(`[CSF Cron] Programado para: ${CSF_CRON_SCHEDULE} (America/Mexico_City)`);
console.log(`[SAT Cron Inc] Incremental Enterprise programado para: ${INCREMENTAL_CRON_SCHEDULE} (America/Mexico_City)`);
console.log(`[SAT Cron Inc] Incremental programado para: ${INCREMENTAL_CRON_SCHEDULE} (America/Mexico_City)`);
console.log(`[Subscription Cron] Lifecycle programado para: ${SUBSCRIPTION_LIFECYCLE_CRON} (America/Mexico_City)`);
console.log(`[SAT Watchdog] Programado para: ${WATCHDOG_CRON_SCHEDULE} (America/Mexico_City)`);
}