-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathresult.js
90 lines (86 loc) · 2.58 KB
/
result.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import nconf from 'nconf';
import { Router } from 'express';
import { getConfigByTestId } from '../../configs.js';
import { getQueueById } from '../../queuehandler.js';
import { getText } from '../../util/text.js';
import { getTest } from '../../database/index.js';
export const result = Router();
result.get('/:id', async function (request, response) {
const id = request.params.id;
const workQueue = getQueueById(id);
if (workQueue) {
const job = await workQueue.getJob(id);
if (job) {
const status = await job.getState();
if (status === 'completed') {
return response.redirect(job.returnvalue.pageSummaryUrl);
} else if (status === 'failed') {
const { logs } = await workQueue.getJobLogs(id);
return response.render('error', {
status: status,
id: id,
logs: logs,
nconf,
message: getText('error.testfailed'),
getText
});
} else {
const testConfig = getConfigByTestId(id);
const count = await workQueue.count();
let placeInQueue = 1;
if (count > 1) {
const jobs = await workQueue.getWaiting(0, 500);
for (let job of jobs) {
if (job.opts.jobId === id) {
break;
} else {
placeInQueue++;
}
}
}
response.header('Cache-Control', 'no-cache, no-store, must-revalidate');
response.header('Pragma', 'no-cache');
response.header('Expires', 0);
return response.render('running', {
status: status,
message:
count > 1
? getText('index.inqueue', count, placeInQueue)
: getText('index.waitingtorunnext'),
id: id,
url: testConfig.url,
nconf,
getText
});
}
} else {
return response.render('error', {
id: id,
nconf,
message: getText('error.validation.nomatchingtestwithid', id),
getText
});
}
} else {
const testResult = await getTest(id);
if (!testResult) {
return response.render('error', {
id: id,
nconf,
message: getText('error.validation.nomatchingtestwithid', id),
getText
});
} else if (testResult.status === 'completed') {
return response.redirect(testResult.result_url);
} else if (testResult.status === 'failed') {
return response.render('error', {
status: testResult,
id: id,
logs: [],
nconf,
message: getText('error.testfailed'),
getText
});
}
}
});