screwdriver-api 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugins/status.js +60 -1
package/package.json
CHANGED
package/plugins/status.js
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const logger = require('screwdriver-logger');
|
|
3
4
|
const schema = require('screwdriver-data-schema');
|
|
5
|
+
const requestRetry = require('screwdriver-request');
|
|
6
|
+
|
|
7
|
+
const RETRY_LIMIT = 2;
|
|
8
|
+
const RETRY_DELAY = 5; // in seconds
|
|
9
|
+
const HTTP_TIMEOUT = 1000; // in ms
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Makes api call to the url endpoint
|
|
13
|
+
* @async invoke
|
|
14
|
+
* @param {String} url
|
|
15
|
+
* @return Promise.resolve
|
|
16
|
+
*/
|
|
17
|
+
async function invoke(url) {
|
|
18
|
+
logger.info(`GET ${url}`);
|
|
19
|
+
|
|
20
|
+
const options = {
|
|
21
|
+
url,
|
|
22
|
+
retry: {
|
|
23
|
+
limit: RETRY_LIMIT,
|
|
24
|
+
calculateDelay: ({ computedValue }) => (computedValue ? RETRY_DELAY * 1000 : 0) // in ms
|
|
25
|
+
},
|
|
26
|
+
method: 'GET',
|
|
27
|
+
responseType: 'text',
|
|
28
|
+
timeout: HTTP_TIMEOUT
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const result = await requestRetry(options);
|
|
33
|
+
|
|
34
|
+
return { code: result.statusCode, body: result.body };
|
|
35
|
+
} catch (err) {
|
|
36
|
+
logger.error(`Failed to get ${url}: ${err.message}`);
|
|
37
|
+
|
|
38
|
+
return { code: err.statusCode, body: err.message };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
4
41
|
|
|
5
42
|
/**
|
|
6
43
|
* Hapi interface for plugin to set up status endpoint (see Hapi docs)
|
|
@@ -14,7 +51,29 @@ const statusPlugin = {
|
|
|
14
51
|
server.route({
|
|
15
52
|
method: 'GET',
|
|
16
53
|
path: '/status',
|
|
17
|
-
handler: (
|
|
54
|
+
handler: async (request, h) => {
|
|
55
|
+
const { exhaustive } = request.query;
|
|
56
|
+
|
|
57
|
+
if (exhaustive) {
|
|
58
|
+
const responses = await Promise.all([
|
|
59
|
+
invoke(`${request.server.app.ecosystem.queue}/v1/status`),
|
|
60
|
+
invoke(`${request.server.app.ecosystem.store}/v1/status`)
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
const response = responses.find(r => r.code !== 200);
|
|
64
|
+
const code = response ? response.code : 200;
|
|
65
|
+
|
|
66
|
+
return h
|
|
67
|
+
.response({
|
|
68
|
+
queue: responses[0].body,
|
|
69
|
+
store: responses[1].body,
|
|
70
|
+
api: 'OK'
|
|
71
|
+
})
|
|
72
|
+
.code(code);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return h.response('OK').code(200);
|
|
76
|
+
},
|
|
18
77
|
config: {
|
|
19
78
|
description: 'API status',
|
|
20
79
|
notes: 'Should respond with 200: ok',
|