-
Notifications
You must be signed in to change notification settings - Fork 136
/
runner.ts
48 lines (33 loc) · 1.25 KB
/
runner.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// local dependencies
import * as db from '../db/store';
import * as processor from './processor';
import * as notifications from '../notifications/slack';
import * as constants from '../utils/constants';
import loggerSetup from '../utils/logger';
import * as Types from '../db/db-types';
const log = loggerSetup();
export async function run(): Promise<void> {
let nextJob: Types.PendingJob | undefined;
try {
const start = new Date();
nextJob = await db.getNextPendingJob();
while (nextJob) {
await processor.processJob(nextJob);
await db.deletePendingJob(nextJob);
nextJob = await db.getNextPendingJob();
}
const end = new Date();
const durationMs = end.getTime() - start.getTime();
log.info({ durationMs }, 'No pending jobs remain');
if (durationMs > constants.THREE_HOURS) {
notifications.notify('Processing pending jobs took longer than THREE HOURS');
}
}
catch (err) {
log.error({ err, nextJob }, 'Pending job failure');
notifications.notify('Critical failure in processing pending jobs: ' + err.message);
if (nextJob) {
db.recordUnsuccessfulPendingJobExecution(nextJob);
}
}
}