-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathjobSchedulerServiceImplementation.js
More file actions
64 lines (57 loc) · 2.01 KB
/
jobSchedulerServiceImplementation.js
File metadata and controls
64 lines (57 loc) · 2.01 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'strict';
const { httpCodes } = require('../lib/codes');
const JobAction = require('../lib/jobSchedulerActionImplementation');
const cds = require('@sap/cds');
module.exports = cds.service.impl(async (srv) => {
srv.before('*', (req) => {
if (
req.headers &&
req.headers['x-sap-job-id'] &&
req.headers['x-sap-job-schedule-id'] &&
req.headers['x-sap-job-run-id']
)
return;
console.error(
`JobScheduler API Endpoint: Required headers of the Job Scheduler Service are missing.`
);
req.error(httpCodes.bad_request, 'ACTION_JOB_GENERATION_FAILED');
});
// ------------------------------------------------------------------------------------
// Action "generateConsumerJobs": Provider job action of Job Scheduler service
// ------------------------------------------------------------------------------------
srv.on('generateConsumerJobs', async (req) => {
try {
const jobAction = new JobAction();
await jobAction.generateConsumerJobs(req);
} catch (e) {
console.error(
`Action generateConsumerJobs: Error while processing jobs: ${e.message}`
);
req.error(
httpCodes.internal_server_error,
'ACTION_JOB_GENERATION_FAILED'
);
}
});
// ------------------------------------------------------------------------------------
// Action "sendReminder": Consumer-specific job action of Job Scheduler service
// ------------------------------------------------------------------------------------
srv.on('sendReminder', async (req) => {
// Manual transaction to directly commit changes to the database
const tx = cds.tx();
try {
const jobAction = new JobAction();
await jobAction.sendReminder(req, tx);
await tx.commit();
} catch (e) {
tx.rollback();
console.error(
`Action sendReminder: Error while processing jobs: ${e.message}`
);
req.error(
httpCodes.internal_server_error,
'ACTION_JOB_REMINDER_SEND_FAIL'
);
}
});
});