d855d55ea0
* re2: fix @trigger.dev/core exports * re2: WIP env based queue selection algo * more wip * WIP * Get run engine tests to pass * Adding tests for the fair dequeueing strat in the run engine * Configure the new queue selection strategy in the webapp and get it all building and typechecks passing * webapp now uses built packages, building redis-worker, run-engine, database, using better tsconfig setups for tests, moving isomorphic code into core/v3/isomorphic * Fixed webapp typechecks * dev now depends on build, fixed supervisor typecheck * Fixed run engine tests * Fixed e2e tests
43 lines
895 B
TypeScript
43 lines
895 B
TypeScript
import { parseNaturalLanguageDuration } from "@trigger.dev/core/v3/isomorphic";
|
|
|
|
export const calculateDurationInMs = (options: {
|
|
seconds?: number;
|
|
minutes?: number;
|
|
hours?: number;
|
|
days?: number;
|
|
}) => {
|
|
return (
|
|
(options?.seconds ?? 0) * 1000 +
|
|
(options?.minutes ?? 0) * 60 * 1000 +
|
|
(options?.hours ?? 0) * 60 * 60 * 1000 +
|
|
(options?.days ?? 0) * 24 * 60 * 60 * 1000
|
|
);
|
|
};
|
|
|
|
export async function parseDelay(value?: string | Date): Promise<Date | undefined> {
|
|
if (!value) {
|
|
return;
|
|
}
|
|
|
|
if (value instanceof Date) {
|
|
return value;
|
|
}
|
|
|
|
try {
|
|
const date = new Date(value);
|
|
|
|
// Check if the date is valid
|
|
if (isNaN(date.getTime())) {
|
|
return parseNaturalLanguageDuration(value);
|
|
}
|
|
|
|
if (date.getTime() <= Date.now()) {
|
|
return;
|
|
}
|
|
|
|
return date;
|
|
} catch (error) {
|
|
return parseNaturalLanguageDuration(value);
|
|
}
|
|
}
|