Skip to content

Commit

Permalink
Fix autoscaled job metric loop
Browse files Browse the repository at this point in the history
  • Loading branch information
nktpro committed Apr 29, 2024
1 parent 8752714 commit e51394c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/apps/k8s_job_autoscaler/libs/autoscaled_job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,18 @@ export async function* watchMetric(
pending: pendingValue ? Number(pendingValue) : 0,
inProgress: inProgressMetric ? (inProgressValue ? Number(inProgressValue) : 0) : null,
};

} catch (error) {
if (!(error instanceof DOMException) || error.name !== "AbortError") {
logger.error({ msg: "Metric query failed", error });
}
} finally {
const now = performance.now();
const elapseMs = now - last;

const toDelayMs = Math.max(maxDelayMs - elapseMs, 0);
if (toDelayMs > 0) {
await delay(toDelayMs);
await delay(toDelayMs, { signal });
}
} catch (error) {
if (!(error instanceof DOMException) || error.name !== "AbortError") {
logger.error({ msg: "Metric query failed", error });
}
} finally {
last = performance.now();
}
}
Expand Down

0 comments on commit e51394c

Please sign in to comment.