feat: Allow configuring category sync interval via environment variable and log next sync time.
This commit is contained in:
@@ -9,4 +9,5 @@ JTL_SHOP_ID=0
|
|||||||
JTL_SPRACHE_ID=1
|
JTL_SPRACHE_ID=1
|
||||||
JTL_PLATTFORM_ID=1
|
JTL_PLATTFORM_ID=1
|
||||||
SERVER_PORT=3991
|
SERVER_PORT=3991
|
||||||
SERVER_HOST=127.0.0.1
|
SERVER_HOST=127.0.0.1
|
||||||
|
SYNC_INTERVAL_MS=600000
|
||||||
@@ -62,6 +62,11 @@ class CategorySyncer extends EventEmitter {
|
|||||||
await this._syncFromDb();
|
await this._syncFromDb();
|
||||||
const duration = Date.now() - startTime;
|
const duration = Date.now() - startTime;
|
||||||
console.log(`✅ Sync completed successfully in ${duration}ms.`);
|
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) {
|
} catch (err) {
|
||||||
console.error('❌ Sync failed:', err);
|
console.error('❌ Sync failed:', err);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
24
index.js
24
index.js
@@ -30,21 +30,17 @@ categorySyncer.on('synced', async ({ tree, unprunedTree, changed }) => {
|
|||||||
// Trigger immediate sync
|
// Trigger immediate sync
|
||||||
categorySyncer.triggerSync();
|
categorySyncer.triggerSync();
|
||||||
|
|
||||||
// Check if running interactively
|
// Schedule periodic sync
|
||||||
if (process.stdout.isTTY) {
|
const syncInterval = parseInt(process.env.SYNC_INTERVAL_MS) || 60000;
|
||||||
console.log('🤖 Interactive mode: Syncing every minute. Press Ctrl-C to exit.');
|
setInterval(() => {
|
||||||
|
categorySyncer.triggerSync();
|
||||||
|
}, syncInterval);
|
||||||
|
|
||||||
// Schedule periodic sync
|
// Handle graceful shutdown
|
||||||
setInterval(() => {
|
process.on('SIGINT', () => {
|
||||||
categorySyncer.triggerSync();
|
console.log('\n👋 Bye!');
|
||||||
}, 60000);
|
process.exit(0);
|
||||||
|
});
|
||||||
// Handle graceful shutdown
|
|
||||||
process.on('SIGINT', () => {
|
|
||||||
console.log('\n👋 Bye!');
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start Express server
|
// Start Express server
|
||||||
startServer();
|
startServer();
|
||||||
|
|||||||
Reference in New Issue
Block a user