9b41a3be54
This Pr begins the extensibility journey - adds a `core.cronTrigger` table - add a oneToMany relation between core.serverlessFunction and `core.cronTrigger` (one serverlessFunction can be triggered by multiple cronTriggers) - add a job to trigger a serverless function - adds a cron to trigger serverlessFunction (via the trigger job) based on the core.cronTrigger.setting.pattern - adds a command to register the cron - add the command in `cron-register-all.command.ts`
21 lines
444 B
TypeScript
21 lines
444 B
TypeScript
import { CronExpressionParser } from 'cron-parser';
|
|
|
|
export const shouldRunNow = (
|
|
pattern: string,
|
|
now: Date,
|
|
rootCronIntervalMs = 60_000,
|
|
) => {
|
|
try {
|
|
const interval = CronExpressionParser.parse(pattern, {
|
|
currentDate: now,
|
|
});
|
|
|
|
const prevTriggerDate = interval.prev();
|
|
const diff = Math.abs(prevTriggerDate.getTime() - now.getTime());
|
|
|
|
return diff < rootCronIntervalMs;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|