allow app-config of the catalog processingInterval
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -85,7 +85,7 @@ describe('readTaskScheduleDefinitionFromConfig', () => {
|
||||
});
|
||||
|
||||
expect(() => readTaskScheduleDefinitionFromConfig(config)).toThrow(
|
||||
'HumanDuration needs at least one of',
|
||||
"Failed to read duration from config at 'frequency', Error: Needs one or more of 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds'",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ describe('readTaskScheduleDefinitionFromConfig', () => {
|
||||
});
|
||||
|
||||
expect(() => readTaskScheduleDefinitionFromConfig(config)).toThrow(
|
||||
"Unable to convert config value for key 'frequency.minutes' in 'mock-config' to a number",
|
||||
"Failed to read duration from config, Error: Unable to convert config value for key 'frequency.minutes' in 'mock-config' to a number",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -112,7 +112,7 @@ describe('readTaskScheduleDefinitionFromConfig', () => {
|
||||
});
|
||||
|
||||
expect(() => readTaskScheduleDefinitionFromConfig(config)).toThrow(
|
||||
'HumanDuration does not contain properties: invalid',
|
||||
"Failed to read duration from config at 'frequency', Error: Unknown property 'invalid'; expected one or more of 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds'",
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -14,54 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Config } from '@backstage/config';
|
||||
import { Config, readDurationFromConfig } from '@backstage/config';
|
||||
import { HumanDuration } from '@backstage/types';
|
||||
import { TaskScheduleDefinition } from './types';
|
||||
import { Duration } from 'luxon';
|
||||
|
||||
const propsOfHumanDuration = [
|
||||
'years',
|
||||
'months',
|
||||
'weeks',
|
||||
'days',
|
||||
'hours',
|
||||
'minutes',
|
||||
'seconds',
|
||||
'milliseconds',
|
||||
];
|
||||
|
||||
function convertToHumanDuration(config: Config, key: string): HumanDuration {
|
||||
// Ensures that the root is an object
|
||||
const root = config.getConfig(key);
|
||||
|
||||
const result: Record<string, number> = {};
|
||||
let found = false;
|
||||
for (const prop of propsOfHumanDuration) {
|
||||
const value = root.getOptionalNumber(prop);
|
||||
if (value !== undefined) {
|
||||
result[prop] = value;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
throw new Error(
|
||||
`HumanDuration needs at least one of: ${propsOfHumanDuration}`,
|
||||
);
|
||||
}
|
||||
|
||||
const invalidProps = root
|
||||
.keys()
|
||||
.filter(prop => !propsOfHumanDuration.includes(prop));
|
||||
if (invalidProps.length > 0) {
|
||||
throw new Error(
|
||||
`HumanDuration does not contain properties: ${invalidProps}`,
|
||||
);
|
||||
}
|
||||
|
||||
return result as HumanDuration;
|
||||
}
|
||||
|
||||
function readDuration(config: Config, key: string): Duration | HumanDuration {
|
||||
if (typeof config.get(key) === 'string') {
|
||||
const value = config.getString(key);
|
||||
@@ -72,7 +29,7 @@ function readDuration(config: Config, key: string): Duration | HumanDuration {
|
||||
return duration;
|
||||
}
|
||||
|
||||
return convertToHumanDuration(config, key);
|
||||
return readDurationFromConfig(config, { key });
|
||||
}
|
||||
|
||||
function readCronOrDuration(
|
||||
|
||||
Reference in New Issue
Block a user