File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,32 @@ import * as fs from 'fs';
3
3
import { DB_FILE_STATUS , JANITOR_COPIES } from '../constants' ;
4
4
import { DatabaseService } from '../services/database.service' ;
5
5
6
+ export async function syncLogsDb ( db : DatabaseService ) {
7
+ console . log ( 'janitor: sync logs with DB records' ) ;
8
+ const result = await db . query < {
9
+ id : number ;
10
+ basename : string ;
11
+ path : string ;
12
+ } > (
13
+ `
14
+ SELECT id, basename, path
15
+ FROM logs
16
+ WHERE status = ?
17
+ ORDER BY id DESC
18
+ ` ,
19
+ [ DB_FILE_STATUS . CopiedToObjectStore ] ,
20
+ ) ;
21
+ for ( const row of result . rows ) {
22
+ try {
23
+ const filePath = row . path ;
24
+ fs . openSync ( `${ filePath } ` , 'r' ) ;
25
+ } catch ( err ) {
26
+ console . log ( `Delete db row id with missing log: ${ row . id } ` ) ;
27
+ db . deleteLog ( row . id ) ;
28
+ }
29
+ }
30
+ }
31
+
6
32
export async function removeOldLogs ( db : DatabaseService ) {
7
33
console . log ( 'janitor: start' ) ;
8
34
const nameHash : { [ key : string ] : number } = { } ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
11
11
import { backup } from './cron/backup' ;
12
12
import { DatabaseService } from './services/database.service' ;
13
13
import { rotateLogs } from './cron/rotate' ;
14
- import { removeOldLogs } from './cron/janitor' ;
14
+ import { removeOldLogs , syncLogsDb } from './cron/janitor' ;
15
15
import { compress } from './cron/compress' ;
16
16
17
17
console . log ( 'Starting...' ) ;
@@ -41,6 +41,7 @@ async function main() {
41
41
await backup ( db ) ;
42
42
} ) ;
43
43
const janitorJob = Cron ( CRON_JANITOR , async ( ) => {
44
+ await syncLogsDb ( db ) ;
44
45
await removeOldLogs ( db ) ;
45
46
} ) ;
46
47
console . log ( `Rotate job next run: ${ rotateJob . nextRun ( ) } ` ) ;
You can’t perform that action at this time.
0 commit comments