diff --git a/entities/webservice.js b/entities/webservice.js index 425a6c7..8753ac5 100644 --- a/entities/webservice.js +++ b/entities/webservice.js @@ -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', + }, + ], + }, }, }, }), diff --git a/index.js b/index.js index 717c22d..84ae197 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/lib/processoutage.js b/lib/processoutage.js index 34c3191..9fb6f6d 100644 --- a/lib/processoutage.js +++ b/lib/processoutage.js @@ -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, diff --git a/lib/runtime.js b/lib/runtime.js index 0017d92..7c7fac5 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -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}`); } }