Skip to content

Commit

Permalink
Merge pull request #4 from bcgov/feat/runJanitorForAllJobs
Browse files Browse the repository at this point in the history
feat: run janitor before all jobs that read files
  • Loading branch information
mbystedt authored Jan 3, 2024
2 parents 3cb8de1 + d2dcae1 commit 3bd48d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cron/janitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export async function syncLogsDb(db: DatabaseService) {
);
for (const row of result.rows) {
try {
const filePath = row.path;
fs.openSync(`${filePath}`, 'r');
fs.openSync(`${row.path}`, 'r');
} catch (err) {
console.log(`janitor: delete database row ${row.id}`);
console.log(
`janitor: delete database row ${row.id}; file missing: ${row.path}`,
);
db.deleteLog(row.id);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ async function main() {
await rotateLogs(db);
});
const compressJob = Cron(CRON_COMPRESS, async () => {
await syncLogsDb(db);
await compress(db);
});
const backupJob = Cron(CRON_BACKUP, async () => {
await syncLogsDb(db);
await backup(db);
});
const janitorJob = Cron(CRON_JANITOR, async () => {
Expand Down

0 comments on commit 3bd48d9

Please sign in to comment.