Spaces:
Paused
Paused
Add GitHub sync service (part 2)
Browse files- server/src/index.ts +1 -0
- server/src/scheduler.ts +29 -1
server/src/index.ts
CHANGED
|
@@ -81,6 +81,7 @@ const onListen = () => {
|
|
| 81 |
scheduler.startTrekPhotoCacheCleanup();
|
| 82 |
scheduler.startPlacePhotoCacheCleanup();
|
| 83 |
scheduler.startAirTrailSync();
|
|
|
|
| 84 |
const { startTokenCleanup } = require('./services/ephemeralTokens');
|
| 85 |
startTokenCleanup();
|
| 86 |
import('./websocket').then(({ setupWebSocket }) => {
|
|
|
|
| 81 |
scheduler.startTrekPhotoCacheCleanup();
|
| 82 |
scheduler.startPlacePhotoCacheCleanup();
|
| 83 |
scheduler.startAirTrailSync();
|
| 84 |
+
scheduler.startGithubSync();
|
| 85 |
const { startTokenCleanup } = require('./services/ephemeralTokens');
|
| 86 |
startTokenCleanup();
|
| 87 |
import('./websocket').then(({ setupWebSocket }) => {
|
server/src/scheduler.ts
CHANGED
|
@@ -408,6 +408,33 @@ function startAirTrailSync(): void {
|
|
| 408 |
}, { timezone: tz });
|
| 409 |
}
|
| 410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
function stop(): void {
|
| 412 |
if (currentTask) { currentTask.stop(); currentTask = null; }
|
| 413 |
if (demoTask) { demoTask.stop(); demoTask = null; }
|
|
@@ -417,6 +444,7 @@ function stop(): void {
|
|
| 417 |
if (trekPhotoCacheTask) { trekPhotoCacheTask.stop(); trekPhotoCacheTask = null; }
|
| 418 |
if (placePhotoCacheTask) { placePhotoCacheTask.stop(); placePhotoCacheTask = null; }
|
| 419 |
if (airtrailSyncTask) { airtrailSyncTask.stop(); airtrailSyncTask = null; }
|
|
|
|
| 420 |
}
|
| 421 |
|
| 422 |
-
export { start, stop, startDemoReset, startTripReminders, startTodoReminders, startVersionCheck, startIdempotencyCleanup, purgeExpiredIdempotencyKeys, startTrekPhotoCacheCleanup, startPlacePhotoCacheCleanup, startAirTrailSync, loadSettings, saveSettings, VALID_INTERVALS };
|
|
|
|
| 408 |
}, { timezone: tz });
|
| 409 |
}
|
| 410 |
|
| 411 |
+
// GitHub sync: periodically push the database to GitHub
|
| 412 |
+
let githubSyncTask: ScheduledTask | null = null;
|
| 413 |
+
|
| 414 |
+
function startGithubSync(): void {
|
| 415 |
+
if (githubSyncTask) { githubSyncTask.stop(); githubSyncTask = null; }
|
| 416 |
+
if (!process.env.PAT_TOKEN) {
|
| 417 |
+
logInfo('GitHub Sync disabled (PAT_TOKEN not set)');
|
| 418 |
+
return;
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
const tz = process.env.TZ || 'UTC';
|
| 422 |
+
// Run every 6 hours
|
| 423 |
+
githubSyncTask = cron.schedule('0 */6 * * *', async () => {
|
| 424 |
+
try {
|
| 425 |
+
const { runGithubSync } = require('./services/githubSyncService');
|
| 426 |
+
await runGithubSync();
|
| 427 |
+
} catch (err: unknown) {
|
| 428 |
+
logError(`GitHub Sync tick failed: ${err instanceof Error ? err.message : err}`);
|
| 429 |
+
}
|
| 430 |
+
}, { timezone: tz });
|
| 431 |
+
logInfo('GitHub Sync scheduled (every 6 hours)');
|
| 432 |
+
|
| 433 |
+
// Also run once on startup
|
| 434 |
+
const { runGithubSync } = require('./services/githubSyncService');
|
| 435 |
+
runGithubSync().catch(err => logError(`Initial GitHub Sync failed: ${err.message}`));
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
function stop(): void {
|
| 439 |
if (currentTask) { currentTask.stop(); currentTask = null; }
|
| 440 |
if (demoTask) { demoTask.stop(); demoTask = null; }
|
|
|
|
| 444 |
if (trekPhotoCacheTask) { trekPhotoCacheTask.stop(); trekPhotoCacheTask = null; }
|
| 445 |
if (placePhotoCacheTask) { placePhotoCacheTask.stop(); placePhotoCacheTask = null; }
|
| 446 |
if (airtrailSyncTask) { airtrailSyncTask.stop(); airtrailSyncTask = null; }
|
| 447 |
+
if (githubSyncTask) { githubSyncTask.stop(); githubSyncTask = null; }
|
| 448 |
}
|
| 449 |
|
| 450 |
+
export { start, stop, startDemoReset, startTripReminders, startTodoReminders, startVersionCheck, startIdempotencyCleanup, purgeExpiredIdempotencyKeys, startTrekPhotoCacheCleanup, startPlacePhotoCacheCleanup, startAirTrailSync, startGithubSync, loadSettings, saveSettings, VALID_INTERVALS };
|