zibri
    Preparing search index...

    Utility class for creating cron expressions with guardrails.

    Index

    Methods

    • Fixes a specific field to a concrete value.

      Type Parameters

      • T extends CronUnit

      Parameters

      • value: RangeForCronUnit<T>

        The concrete value.

      • unit: T

        The unit, like 'minutes', 'hours', 'days' etc.

      Returns CronExpression

      A cron expression to either continue working with or building the result string.

      CronExpression.every(1, 'hours').at(30, 'minutes')  // "* 30 * * * *" (at :30 past every hour)
      CronExpression.daily().at(9, 'hours') // "0 0 9 * * *"
    • Restricts execution to a range of values for a given unit.

      Type Parameters

      • T extends CronUnit

      Parameters

      • from: RangeForCronUnit<T>

        The value at which the range starts.

      • to: RangeForCronUnit<T>

        The value at which the range ends.

      • unit: T

        The unit, like 'minutes', 'hours', 'days' etc.

      Returns CronExpression

      A cron expression to either continue working with or building the result string.

      CronExpression.every(1, 'minutes').between(9, 17, 'hours')  // "* * 9-17 * * *" (business hours only)
      

      If the "from" value is smaller than the "to" value.

    • Restricts execution to specific months.

      Parameters

      • ...months: [MonthName, ...MonthName[]]

        The months in which the execution should happen.

      Returns CronExpression

      A cron expression to either continue working with or building the result string.

      CronExpression.monthly().in('March', 'June', 'September', 'December')  // "0 0 0 1 3,6,9,12 *"
      
    • Restricts execution to specific days of the week.

      Parameters

      • ...days: [DayOfWeek, ...DayOfWeek[]]

        The days on which the execution should happen.

      Returns CronExpression

      A cron expression to either continue working with or building the result string.

      CronExpression.daily().on('Monday', 'Wednesday', 'Friday')  // "0 0 0 * * 1,3,5"
      
    • Runs every N units.

      Type Parameters

      • T extends CronUnit

      Parameters

      • value: RangeForCronUnit<T>

        The interval at which to run.

      • unit: T

        The unit, like 'minutes', 'hours', 'days' etc.

      Returns CronExpression

      A cron expression to either continue working with or building the result string.

      CronExpression.every(5, 'minutes')  // "* */5 * * * *"
      CronExpression.every(2, 'hours') // "* * */2 * * *"