core.isvalidcronstring
Home > @medplum/core > isValidCronString
isValidCronString() function
Returns true if the input is a cron expression the Medplum job scheduler can run.
Accepts what cron-parser accepts in its default, non-strict mode -- the @daily-style shorthands, month and weekday names, and the L, #, and ? extensions -- with these restrictions:
- The empty string, which cron-parser reads as every minute but BullMQ refuses as a missing pattern, is rejected. - An expression BullMQ cannot compute a next run for is rejected, since it would silently schedule nothing: one that can never fire, such as
0 0 31 4,6 *, or the 5th weekday of February, such as0 0 * 2 1#5. - Schedules are limited to minute granularity, so the optional sixth (seconds) field and@secondlyare rejected. -H(hashed) terms are rejected. They exist to stagger jobs that share a schedule; leaving them out keeps staggering an implementation detail of the scheduler and keeps the syntax authors ofCronandBotresources must learn small. cron-parser also draws them at random, so one expression could pass on one parse and fail on the next.
Signature:
export declare function isValidCronString(cronString: string): boolean;
Parameters
Parameter | Type | Description |
|---|---|---|
cronString | string | The cron expression to check. |
Returns:
boolean
True if the cron expression is valid.