introduce durationToMilliseconds
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
+2
-23
@@ -16,32 +16,11 @@
|
||||
|
||||
import { LifecycleService } from '@backstage/backend-plugin-api';
|
||||
import { ServiceUnavailableError } from '@backstage/errors';
|
||||
import { HumanDuration } from '@backstage/types';
|
||||
import { HumanDuration, durationToMilliseconds } from '@backstage/types';
|
||||
import { RequestHandler } from 'express';
|
||||
|
||||
export const DEFAULT_TIMEOUT = { seconds: 5 };
|
||||
|
||||
function durationToMs(duration: HumanDuration): number {
|
||||
const {
|
||||
years = 0,
|
||||
months = 0,
|
||||
weeks = 0,
|
||||
days = 0,
|
||||
hours = 0,
|
||||
minutes = 0,
|
||||
seconds = 0,
|
||||
milliseconds = 0,
|
||||
} = duration;
|
||||
|
||||
const totalDays = years * 365 + months * 30 + weeks * 7 + days;
|
||||
const totalHours = totalDays * 24 + hours;
|
||||
const totalMinutes = totalHours * 60 + minutes;
|
||||
const totalSeconds = totalMinutes * 60 + seconds;
|
||||
const totalMilliseconds = totalSeconds * 1000 + milliseconds;
|
||||
|
||||
return totalMilliseconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for {@link createLifecycleMiddleware}.
|
||||
* @public
|
||||
@@ -102,7 +81,7 @@ export function createLifecycleMiddleware(
|
||||
waiting.clear();
|
||||
});
|
||||
|
||||
const timeoutMs = durationToMs(startupRequestPauseTimeout);
|
||||
const timeoutMs = durationToMilliseconds(startupRequestPauseTimeout);
|
||||
|
||||
return (_req, _res, next) => {
|
||||
if (state === 'up') {
|
||||
|
||||
Reference in New Issue
Block a user