introduce durationToMilliseconds
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
|
||||
import { ResponseError } from '@backstage/errors';
|
||||
import { HumanDuration, JsonObject } from '@backstage/types';
|
||||
import {
|
||||
HumanDuration,
|
||||
JsonObject,
|
||||
durationToMilliseconds,
|
||||
} from '@backstage/types';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import fetch from 'node-fetch';
|
||||
import yaml from 'yaml';
|
||||
@@ -29,27 +33,6 @@ import {
|
||||
|
||||
const DEFAULT_RELOAD_INTERVAL = { seconds: 60 };
|
||||
|
||||
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 RemoteConfigSource.create}.
|
||||
*
|
||||
@@ -104,7 +87,7 @@ export class RemoteConfigSource implements ConfigSource {
|
||||
|
||||
private constructor(options: RemoteConfigSourceOptions) {
|
||||
this.#url = options.url;
|
||||
this.#reloadIntervalMs = durationToMs(
|
||||
this.#reloadIntervalMs = durationToMilliseconds(
|
||||
options.reloadInterval ?? DEFAULT_RELOAD_INTERVAL,
|
||||
);
|
||||
this.#transformer = createConfigTransformer({
|
||||
|
||||
Reference in New Issue
Block a user