"Test now" button

This commit is contained in:
Romein van Buren 2022-07-22 14:40:31 +02:00
parent af17f80fe1
commit 232c8a73d5
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
3 changed files with 45 additions and 3 deletions

View File

@ -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,
},
],
},
},
},
}),

View File

@ -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',

View File

@ -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