Skip to content

Commit

Permalink
Merge pull request #3 from bcgov/feat/syncFilesDb
Browse files Browse the repository at this point in the history
Sync database for all statuses
  • Loading branch information
andrwils authored Dec 22, 2023
2 parents 058b1f8 + 8b3d3fb commit f1f99ae
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/cron/janitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DB_FILE_STATUS, JANITOR_COPIES } from '../constants';
import { DatabaseService } from '../services/database.service';

export async function syncLogsDb(db: DatabaseService) {
console.log('janitor: sync logs with DB records');
console.log('janitor: sync database records');
const result = await db.query<{
id: number;
basename: string;
Expand All @@ -13,17 +13,16 @@ export async function syncLogsDb(db: DatabaseService) {
`
SELECT id, basename, path
FROM logs
WHERE status = ?
WHERE status >= 0
ORDER BY id DESC
`,
[DB_FILE_STATUS.CopiedToObjectStore],
);
for (const row of result.rows) {
try {
const filePath = row.path;
fs.openSync(`${filePath}`, 'r');
} catch (err) {
console.log(`Delete db row id with missing log: ${row.id}`);
console.log(`janitor: delete database row ${row.id}`);
db.deleteLog(row.id);
}
}
Expand Down

0 comments on commit f1f99ae

Please sign in to comment.