-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (50 loc) · 1.75 KB
/
index.js
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
const { coreLogic } = require('./coreLogic');
const { app } = require('./init');
const {
namespaceWrapper,
taskNodeAdministered,
} = require('./namespaceWrapper');
/**
* setup
* @description sets up the task node, particularly the inter-process communication to start and stop the task
* @returns {void}
*/
async function setup() {
console.log('setup function called');
// Run default setup
await namespaceWrapper.defaultTaskSetup();
process.on('message', m => {
console.log('CHILD got message:', m);
if (m.functionCall == 'submitPayload') {
console.log('submitPayload called');
coreLogic.submitTask(m.roundNumber);
} else if (m.functionCall == 'auditPayload') {
console.log('auditPayload called');
coreLogic.auditTask(m.roundNumber);
} else if (m.functionCall == 'executeTask') {
console.log('executeTask called');
coreLogic.task(m.roundNumber);
} else if (m.functionCall == 'generateAndSubmitDistributionList') {
console.log('generateAndSubmitDistributionList called');
coreLogic.selectAndGenerateDistributionList(m.roundNumber, m.isPreviousRoundFailed);
} else if (m.functionCall == 'distributionListAudit') {
console.log('distributionListAudit called');
coreLogic.auditDistribution(m.roundNumber, m.isPreviousRoundFailed);
}
});
}
if (taskNodeAdministered) {
setup();
}
if (app) {
// Write your Express Endpoints here.
// For Example
// app.post('/accept-cid', async (req, res) => {})
// Sample API that return your task state
app.get('/taskState', async (req, res) => {
const state = await namespaceWrapper.getTaskState();
console.log('TASK STATE', state);
res.status(200).json({ taskState: state });
});
app.use('/api/', require('./routes') );
}