mirror of
https://github.com/smartyellow/status.git
synced 2024-11-21 15:18:55 +01:00
"Test now" button
This commit is contained in:
parent
af17f80fe1
commit
232c8a73d5
@ -34,6 +34,7 @@ module.exports = {
|
||||
{ label: 'endpoints to test',
|
||||
sections: [
|
||||
'autotestInterval',
|
||||
'testNow',
|
||||
'autotest',
|
||||
],
|
||||
},
|
||||
@ -206,6 +207,19 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
testNow: {
|
||||
label: 'test now',
|
||||
fields: [
|
||||
{ key: 'id',
|
||||
label: 'click to test this endpoint now',
|
||||
editor: 'button',
|
||||
method: 'post',
|
||||
url: '/status/webservices/:id/testnow',
|
||||
translate: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
26
index.js
26
index.js
@ -235,7 +235,7 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
|
||||
routes: ({ server }) => [
|
||||
routes: ({ server, settings }) => [
|
||||
|
||||
// Get all services
|
||||
{ route: '/status/webservices',
|
||||
@ -286,6 +286,30 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
|
||||
{ route: '/status/webservices/:id/testnow',
|
||||
method: 'post',
|
||||
requires: 'smartyellow/status/editServices',
|
||||
handler: async (req, res, user) => {
|
||||
const item = await server.storage({ user }).store('smartyellow/webservice').get(req.params[0]);
|
||||
const runtime = fork(__dirname + '/lib/runtime.js');
|
||||
runtime.send({ command: 'testOne', service: item });
|
||||
runtime.on('message', async message => {
|
||||
res.json(message);
|
||||
if (message.error) {
|
||||
server.error(message.error);
|
||||
}
|
||||
else if (message.outage) {
|
||||
await processOutage({
|
||||
outage: { [item.id]: message.outage },
|
||||
onDateUpdated: () => server.publish('cms', 'smartyellow/status/reload'),
|
||||
server,
|
||||
settings,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
{ route: '/status/webservices/search',
|
||||
method: 'post',
|
||||
requires: 'smartyellow/status/seeServices',
|
||||
|
@ -2,13 +2,17 @@
|
||||
|
||||
const { makeId } = require('core/makeid');
|
||||
|
||||
async function processOutage({ outage, server, settings }) {
|
||||
async function processOutage({ outage, server, settings, onDateUpdated }) {
|
||||
if (typeof onDateUpdated !== 'function') {
|
||||
onDateUpdated = () => null;
|
||||
}
|
||||
|
||||
for (const [ id, testResult ] of Object.entries(outage)) {
|
||||
// Update check date
|
||||
server.storage.store('smartyellow/webservice').update(
|
||||
{ id },
|
||||
{ $set: { lastChecked: new Date() } }
|
||||
);
|
||||
).then(() => onDateUpdated(id));
|
||||
|
||||
// Get service entry
|
||||
const service = await server
|
||||
|
Loading…
Reference in New Issue
Block a user