-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add options for compress and run once #20
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,30 +28,58 @@ async function main() { | |
'when launching node to enable forced garbage collection.', | ||
); | ||
} | ||
const runOnce = process.env.RUN_ONCE === 'true'; | ||
const compressEnabled = process.env.COMPRESS_ENABLED === 'true'; | ||
|
||
const rotateJob = Cron(CRON_ROTATE, async () => { | ||
const combinedJob = async () => { | ||
// Stage 1: Rotate log | ||
await rotateLogs(db); | ||
runGarbageCollection(); | ||
}); | ||
const compressJob = Cron(CRON_COMPRESS, async () => { | ||
await syncLogsDb(db); | ||
await compress(db); | ||
runGarbageCollection(); | ||
}); | ||
const backupJob = Cron(CRON_BACKUP, async () => { | ||
|
||
// Stage 2: Compress files - optional | ||
if (compressEnabled) { | ||
await syncLogsDb(db); | ||
await compress(db); | ||
} | ||
|
||
// Stage 3: Backup | ||
await syncLogsDb(db); | ||
await backup(db); | ||
runGarbageCollection(); | ||
}); | ||
const janitorJob = Cron(CRON_JANITOR, async () => { | ||
|
||
// Stage 4: Janitor | ||
await syncLogsDb(db); | ||
await removeOldLogs(db); | ||
runGarbageCollection(); | ||
}); | ||
console.log(`Rotate job next run: ${rotateJob.nextRun()}`); | ||
console.log(`Compress job next run: ${compressJob.nextRun()}`); | ||
console.log(`Backup job next run: ${backupJob.nextRun()}`); | ||
console.log(`Janitor job next run: ${janitorJob.nextRun()}`); | ||
}; | ||
|
||
if (runOnce) combinedJob(); | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is one a function call and the other not? |
||
const rotateJob = Cron(CRON_ROTATE, async () => { | ||
await rotateLogs(db); | ||
runGarbageCollection(); | ||
}); | ||
|
||
if (compressEnabled) { | ||
const compressJob = Cron(CRON_COMPRESS, async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove duplication of compress job (and other jobs) code |
||
await syncLogsDb(db); | ||
await compress(db); | ||
runGarbageCollection(); | ||
}); | ||
console.log(`Compress job next run: ${compressJob.nextRun()}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should output after Backup job text |
||
} | ||
const backupJob = Cron(CRON_BACKUP, async () => { | ||
await syncLogsDb(db); | ||
await backup(db); | ||
runGarbageCollection(); | ||
}); | ||
const janitorJob = Cron(CRON_JANITOR, async () => { | ||
await syncLogsDb(db); | ||
await removeOldLogs(db); | ||
runGarbageCollection(); | ||
}); | ||
console.log(`Rotate job next run: ${rotateJob.nextRun()}`); | ||
console.log(`Backup job next run: ${backupJob.nextRun()}`); | ||
console.log(`Janitor job next run: ${janitorJob.nextRun()}`); | ||
} | ||
} | ||
|
||
main(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will never reach stage 3 if compress disabled.