Skip to content

Commit 3bd48d9

Browse files
authored
Merge pull request #4 from bcgov/feat/runJanitorForAllJobs
feat: run janitor before all jobs that read files
2 parents 3cb8de1 + d2dcae1 commit 3bd48d9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/cron/janitor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export async function syncLogsDb(db: DatabaseService) {
1919
);
2020
for (const row of result.rows) {
2121
try {
22-
const filePath = row.path;
23-
fs.openSync(`${filePath}`, 'r');
22+
fs.openSync(`${row.path}`, 'r');
2423
} catch (err) {
25-
console.log(`janitor: delete database row ${row.id}`);
24+
console.log(
25+
`janitor: delete database row ${row.id}; file missing: ${row.path}`,
26+
);
2627
db.deleteLog(row.id);
2728
}
2829
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ async function main() {
3535
await rotateLogs(db);
3636
});
3737
const compressJob = Cron(CRON_COMPRESS, async () => {
38+
await syncLogsDb(db);
3839
await compress(db);
3940
});
4041
const backupJob = Cron(CRON_BACKUP, async () => {
42+
await syncLogsDb(db);
4143
await backup(db);
4244
});
4345
const janitorJob = Cron(CRON_JANITOR, async () => {

0 commit comments

Comments
 (0)