feat: añadir scheduler de grupos y arrancarlo al iniciar el servicio

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
pull/1/head
brobert 1 month ago
parent 098e135b11
commit 029a632e9d

@ -411,6 +411,14 @@ export class WebhookServer {
// Initialize groups - critical for operation // Initialize groups - critical for operation
await GroupSyncService.checkInitialGroups(); await GroupSyncService.checkInitialGroups();
// Start groups scheduler (periodic sync of groups)
try {
GroupSyncService.startGroupsScheduler();
console.log('✅ Group scheduler started');
} catch (e) {
console.error('⚠️ Failed to start Group scheduler:', e);
}
// Initial members sync (non-blocking if fails) // Initial members sync (non-blocking if fails)
try { try {
await GroupSyncService.syncMembersForActiveGroups(); await GroupSyncService.syncMembersForActiveGroups();

@ -66,6 +66,8 @@ export class GroupSyncService {
return interval; return interval;
} }
private static lastSyncAttempt = 0; private static lastSyncAttempt = 0;
private static _groupsTimer: any = null;
private static _groupsSchedulerRunning = false;
private static _membersTimer: any = null; private static _membersTimer: any = null;
private static _membersSchedulerRunning = false; private static _membersSchedulerRunning = false;
@ -615,6 +617,35 @@ export class GroupSyncService {
this.cacheActiveGroups(); this.cacheActiveGroups();
} }
public static startGroupsScheduler(): void {
if (process.env.NODE_ENV === 'test') return;
if (this._groupsSchedulerRunning) return;
this._groupsSchedulerRunning = true;
// Intervalo de grupos configurable; mínimo 10s en desarrollo
let interval = Number(process.env.GROUP_SYNC_INTERVAL_MS);
if (!Number.isFinite(interval) || interval <= 0) {
interval = 24 * 60 * 60 * 1000; // 24h por defecto
}
if (process.env.NODE_ENV === 'development' && interval < 10000) {
interval = 10000;
}
this._groupsTimer = setInterval(() => {
this.syncGroups().catch(err => {
console.error('❌ Groups scheduler run error:', err);
});
}, interval);
}
public static stopGroupsScheduler(): void {
this._groupsSchedulerRunning = false;
if (this._groupsTimer) {
clearInterval(this._groupsTimer);
this._groupsTimer = null;
}
}
public static startMembersScheduler(): void { public static startMembersScheduler(): void {
if (process.env.NODE_ENV === 'test') return; if (process.env.NODE_ENV === 'test') return;
if (this._membersSchedulerRunning) return; if (this._membersSchedulerRunning) return;

Loading…
Cancel
Save