diff --git a/.env.example b/.env.example index aa2557e..a32af01 100644 --- a/.env.example +++ b/.env.example @@ -9,4 +9,5 @@ JTL_SHOP_ID=0 JTL_SPRACHE_ID=1 JTL_PLATTFORM_ID=1 SERVER_PORT=3991 -SERVER_HOST=127.0.0.1 \ No newline at end of file +SERVER_HOST=127.0.0.1 +SYNC_INTERVAL_MS=600000 \ No newline at end of file diff --git a/category-syncer.js b/category-syncer.js index a3e4251..dea5241 100644 --- a/category-syncer.js +++ b/category-syncer.js @@ -62,6 +62,11 @@ class CategorySyncer extends EventEmitter { await this._syncFromDb(); const duration = Date.now() - startTime; console.log(`āœ… Sync completed successfully in ${duration}ms.`); + + // Log next sync time + const syncInterval = parseInt(process.env.SYNC_INTERVAL_MS) || 60000; + const minutes = Math.round(syncInterval / 60000); + console.log(`ā° Next sync in ${minutes} minute${minutes !== 1 ? 's' : ''}`); } catch (err) { console.error('āŒ Sync failed:', err); } finally { diff --git a/index.js b/index.js index e171987..f4a4926 100644 --- a/index.js +++ b/index.js @@ -30,21 +30,17 @@ categorySyncer.on('synced', async ({ tree, unprunedTree, changed }) => { // Trigger immediate sync categorySyncer.triggerSync(); -// Check if running interactively -if (process.stdout.isTTY) { - console.log('šŸ¤– Interactive mode: Syncing every minute. Press Ctrl-C to exit.'); +// Schedule periodic sync +const syncInterval = parseInt(process.env.SYNC_INTERVAL_MS) || 60000; +setInterval(() => { + categorySyncer.triggerSync(); +}, syncInterval); - // Schedule periodic sync - setInterval(() => { - categorySyncer.triggerSync(); - }, 60000); - - // Handle graceful shutdown - process.on('SIGINT', () => { - console.log('\nšŸ‘‹ Bye!'); - process.exit(0); - }); -} +// Handle graceful shutdown +process.on('SIGINT', () => { + console.log('\nšŸ‘‹ Bye!'); + process.exit(0); +}); // Start Express server startServer();