From 73fdf950dd895d6c95891231a563483d9b3e6226 Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Sun, 30 Mar 2025 00:10:38 +0100 Subject: [PATCH] feat: make group sync interval configurable via env var --- .env.example | 4 ++++ src/services/group-sync.ts | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 538a23a..c405a12 100644 --- a/.env.example +++ b/.env.example @@ -6,3 +6,7 @@ WHATSAPP_COMMUNITY_ID="example-community-id@g.us" CHATBOT_PHONE_NUMBER="1234567890" PORT="3007" WEBHOOK_URL="https://example-url.com/webhook" + +# Group sync interval in milliseconds (default: 24h) +# Set lower during development (e.g. 60000 = 1 minute) +# GROUP_SYNC_INTERVAL_MS=86400000 diff --git a/src/services/group-sync.ts b/src/services/group-sync.ts index bfe4b11..c8469de 100644 --- a/src/services/group-sync.ts +++ b/src/services/group-sync.ts @@ -10,7 +10,18 @@ type EvolutionGroup = { }; export class GroupSyncService { - private static readonly SYNC_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24 hours + private static get SYNC_INTERVAL_MS(): number { + const interval = process.env.GROUP_SYNC_INTERVAL_MS + ? Number(process.env.GROUP_SYNC_INTERVAL_MS) + : 24 * 60 * 60 * 1000; // Default 24 hours + + // Ensure minimum 10 second interval in development + if (process.env.NODE_ENV === 'development' && interval < 10000) { + console.warn(`Sync interval too low (${interval}ms), using 10s minimum`); + return 10000; + } + return interval; + } private static lastSyncAttempt = 0; static async syncGroups(): Promise<{ added: number; updated: number }> {