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',
sections: [
'autotestEnabled',
'autotestInterval',
'lastChecked',
'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: {
autotestInterval: {
type: 'number',
label: 'autotest interval',
description: 'Autotest interval in minutes.',
default: 10,
},
emailSender: {
type: 'string',
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: {
components: [
'formautotestfield.svelte',
@ -183,7 +168,7 @@ module.exports = {
mandatory: false,
runAtBoot: true,
active: true,
interval: Number(settings.autotestInterval) * 60 * 1000,
interval: 60 * 1000,
action: async () => {
const services = await server
.storage

View File

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

View File

@ -11,10 +11,20 @@ process.on('message', async message => {
else {
const ids = [];
const promises = [];
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);
promises.push(testEndpoints(service.autotest));
console.log(`testing ${service.id}`);
}
}