@@ -31,54 +31,58 @@ async function main() {
31
31
const runOnce = process . env . RUN_ONCE === 'true' ;
32
32
const compressEnabled = process . env . COMPRESS_ENABLED === 'true' ;
33
33
34
- const combinedJob = async ( ) => {
35
- // Stage 1: Rotate log
34
+ const rotateJob = async ( ) => {
36
35
await rotateLogs ( db ) ;
36
+ runGarbageCollection ( ) ;
37
+ } ;
37
38
38
- // Stage 2: Compress files - optional
39
- if ( compressEnabled ) {
40
- await syncLogsDb ( db ) ;
41
- await compress ( db ) ;
42
- }
39
+ const compressEnabledJob = async ( ) => {
40
+ await syncLogsDb ( db ) ;
41
+ await compress ( db ) ;
42
+ runGarbageCollection ( ) ;
43
+ } ;
43
44
44
- // Stage 3: Backup
45
+ const backupJob = async ( ) => {
45
46
await syncLogsDb ( db ) ;
46
47
await backup ( db ) ;
48
+ runGarbageCollection ( ) ;
49
+ } ;
47
50
48
- // Stage 4: Janitor
51
+ const janitorJob = async ( ) => {
49
52
await syncLogsDb ( db ) ;
50
53
await removeOldLogs ( db ) ;
51
54
runGarbageCollection ( ) ;
52
55
} ;
53
56
57
+ const combinedJob = async ( ) => {
58
+ // Stage 1: Rotate log
59
+ rotateJob ( ) ;
60
+
61
+ // Stage 2: Compress files - optional
62
+ // Stage 3: Backup - if compress enabled
63
+ if ( compressEnabled ) {
64
+ compressEnabledJob ( ) ;
65
+ backupJob ( ) ;
66
+ }
67
+
68
+ // Stage 4: Janitor
69
+ janitorJob ( ) ;
70
+ } ;
71
+
54
72
if ( runOnce ) combinedJob ( ) ;
55
73
else {
56
- const rotateJob = Cron ( CRON_ROTATE , async ( ) => {
57
- await rotateLogs ( db ) ;
58
- runGarbageCollection ( ) ;
59
- } ) ;
74
+ const rotateCronJob = Cron ( CRON_ROTATE , rotateJob ) ;
60
75
61
76
if ( compressEnabled ) {
62
- const compressJob = Cron ( CRON_COMPRESS , async ( ) => {
63
- await syncLogsDb ( db ) ;
64
- await compress ( db ) ;
65
- runGarbageCollection ( ) ;
66
- } ) ;
67
- console . log ( `Compress job next run: ${ compressJob . nextRun ( ) } ` ) ;
77
+ const compressCronJob = Cron ( CRON_COMPRESS , compressEnabledJob ) ;
78
+ const backupCronJob = Cron ( CRON_BACKUP , backupJob ) ;
79
+ console . log ( `Compress job next run: ${ compressCronJob . nextRun ( ) } ` ) ;
80
+ console . log ( `Backup job next run: ${ backupCronJob . nextRun ( ) } ` ) ;
68
81
}
69
- const backupJob = Cron ( CRON_BACKUP , async ( ) => {
70
- await syncLogsDb ( db ) ;
71
- await backup ( db ) ;
72
- runGarbageCollection ( ) ;
73
- } ) ;
74
- const janitorJob = Cron ( CRON_JANITOR , async ( ) => {
75
- await syncLogsDb ( db ) ;
76
- await removeOldLogs ( db ) ;
77
- runGarbageCollection ( ) ;
78
- } ) ;
79
- console . log ( `Rotate job next run: ${ rotateJob . nextRun ( ) } ` ) ;
80
- console . log ( `Backup job next run: ${ backupJob . nextRun ( ) } ` ) ;
81
- console . log ( `Janitor job next run: ${ janitorJob . nextRun ( ) } ` ) ;
82
+
83
+ const janitorCronJob = Cron ( CRON_JANITOR , janitorJob ) ;
84
+ console . log ( `Rotate job next run: ${ rotateCronJob . nextRun ( ) } ` ) ;
85
+ console . log ( `Janitor job next run: ${ janitorCronJob . nextRun ( ) } ` ) ;
82
86
}
83
87
}
84
88
0 commit comments