Define test interval separately for each service

Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
Romein van Buren 2022-07-11 12:52:42 +02:00
parent 14213d3ee2
commit 09a7df98e6
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
4 changed files with 26 additions and 18 deletions

View File

@ -38,6 +38,7 @@ module.exports = {
{ label: 'auto testing', { label: 'auto testing',
sections: [ sections: [
'autotestEnabled', 'autotestEnabled',
'autotestInterval',
'lastChecked', 'lastChecked',
'autotest', 'autotest',
], ],
@ -216,6 +217,18 @@ module.exports = {
}, },
], ],
}, },
autotestInterval: {
label: 'test interval',
hint: 'Interval between 2 automatic tests in minutes.',
fields: [
{ key: 'autotestInterval',
editor: 'number',
label: 'minutes',
labelPosition: 'right',
},
],
},
}, },
}, },
}), }),

View File

@ -84,12 +84,6 @@ module.exports = {
}, },
settings: { settings: {
autotestInterval: {
type: 'number',
label: 'autotest interval',
description: 'Autotest interval in minutes.',
default: 10,
},
emailSender: { emailSender: {
type: 'string', type: 'string',
label: 'notification sender', label: 'notification sender',
@ -122,15 +116,6 @@ module.exports = {
}, },
}, },
init: async ({ server, settings }) => {
settings.autotestInterval = Number(settings.autotestInterval);
if (Number.isNaN(settings.autotestInterval)) {
server.warn('status: settings.autotestInterval is not a number. Using default value 10.');
settings.autotestInterval = 10;
}
return true;
},
gui: { gui: {
components: [ components: [
'formautotestfield.svelte', 'formautotestfield.svelte',
@ -183,7 +168,7 @@ module.exports = {
mandatory: false, mandatory: false,
runAtBoot: true, runAtBoot: true,
active: true, active: true,
interval: Number(settings.autotestInterval) * 60 * 1000, interval: 60 * 1000,
action: async () => { action: async () => {
const services = await server const services = await server
.storage .storage

View File

@ -78,7 +78,7 @@ async function processOutage({ outage, server, settings }) {
.insert({ .insert({
id: makeId(6), id: makeId(6),
name: { name: {
en: `[automatic] Outage for ${service.name}`, en: `[automatic] Outage for ${service.name.en}`,
}, },
state: 'concept', state: 'concept',
resolved: false, resolved: false,

View File

@ -11,10 +11,20 @@ process.on('message', async message => {
else { else {
const ids = []; const ids = [];
const promises = []; const promises = [];
for (const service of message.services) { for (const service of message.services) {
if (service.autotestEnabled) { const lastChecked = new Date(service.lastChecked);
let timePassed = new Date().getTime() - lastChecked.getTime();
timePassed = timePassed / 1000 / 60;
const interval = service.autotestInterval;
const needsCheck = timePassed >= interval;
console.log(`service ${service.id}`, lastChecked, service.autotestEnabled, timePassed, interval, needsCheck);
if (service.autotestEnabled && needsCheck) {
ids.push(service.id); ids.push(service.id);
promises.push(testEndpoints(service.autotest)); promises.push(testEndpoints(service.autotest));
console.log(`testing ${service.id}`);
} }
} }