mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-16 23:38:52 +00:00
Fix target poll healthcheck
The Target.lastFetch time compared when performing the healthcheck resets any time a poll is attempted no matter the outcome. This changes the behavior so the time is reset only on a successful poll Change-type: patch
This commit is contained in:
parent
c88cf6a259
commit
f8bdb14335
@ -63,7 +63,7 @@ export async function healthcheck() {
|
||||
}
|
||||
|
||||
// Check last time target state has been polled
|
||||
const timeSinceLastFetch = process.hrtime(TargetState.lastFetch);
|
||||
const timeSinceLastFetch = process.hrtime(TargetState.lastSuccessfulFetch);
|
||||
const timeSinceLastFetchMs =
|
||||
timeSinceLastFetch[0] * 1000 + timeSinceLastFetch[1] / 1e6;
|
||||
|
||||
|
@ -87,7 +87,8 @@ const emitTargetState = (
|
||||
* We set a value rather then being undeclared because having it undefined
|
||||
* adds more overhead to dealing with this value without any benefits.
|
||||
*/
|
||||
export let lastFetch: ReturnType<typeof process.hrtime> = process.hrtime();
|
||||
export let lastSuccessfulFetch: ReturnType<typeof process.hrtime> =
|
||||
process.hrtime();
|
||||
|
||||
/**
|
||||
* Attempts to update the target state
|
||||
@ -154,8 +155,6 @@ export const update = async (
|
||||
|
||||
// Emit the target state and update the cache
|
||||
cache.emitted = emitTargetState(cache, force, isFromApi);
|
||||
}).finally(() => {
|
||||
lastFetch = process.hrtime();
|
||||
});
|
||||
};
|
||||
|
||||
@ -188,6 +187,7 @@ const poll = async (
|
||||
await update();
|
||||
// Reset fetchErrors because we successfuly updated
|
||||
fetchErrors = 0;
|
||||
lastSuccessfulFetch = process.hrtime();
|
||||
} catch {
|
||||
// Exponential back off if request fails
|
||||
pollInterval = Math.min(appUpdatePollInterval, 15000 * 2 ** fetchErrors);
|
||||
|
@ -335,7 +335,7 @@ describe('ApiBinder', () => {
|
||||
|
||||
before(async () => {
|
||||
await initModels(components, '/config-apibinder.json');
|
||||
previousLastFetch = TargetState.lastFetch;
|
||||
previousLastFetch = TargetState.lastSuccessfulFetch;
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user