Articles in this section
Category / Section

How to Create a Schedule Using Preset and CRON Expression

Published:

Scheduled reports offer two modes for defining a schedule for report generation: Basic and Custom.

Basic mode offers predefined scheduling options such as:

  1. Once- To run a single time at a specified date and time.

  2. Daily- To run every day at a specified time.

  3. Weekly- To run on specific days of the week at a specified time.

  4. Monthly- To run on specific days of the month at a specified time.

In Custom mode, define a Cron expression for precise recurrence that may not be achieved in the Basic mode.

A Cron expression is a string used to define a schedule for running tasks at specific times and intervals. It consists of five or six fields representing the timing for the task.

Common instructions for basic mode

  1. Start Date and Time: Must be selected for all options.

  2. End Date: This option is available for Daily, Weekly, and Monthly options. It is optional and useful if the scheduler needs to run for a specific period before stopping.

  3. Scheduler Timing: The scheduler must be set to trigger at least 15 minutes from the current time (based on the selected time zone). This is mandatory for the Once type. For other types, if the next occurrence is within 15 minutes, it will skip to the next valid occurrence.

Configuration for each option

  1. Once:

    Start Date and Time: Choose when the report should be generated once.

    Screenshot 2024-07-28 142443.png

  2. Daily: Choose the start date and time.

    Screenshot 2024-07-28 142603.png

  3. Weekly: Choose the start date and time.

    Days of the Week: Select the days of the week (Sunday to Saturday) when the report should be generated.

    Screenshot 2024-07-28 142055.png

  4. Monthly: Choose the start date and time.

    Days of the Month: Select the days of the month (1 to 31) when the report should be generated.

    Screenshot 2024-07-28 142245.png

How to configure custom mode

Screenshot 2024-07-28 141237.png

In our case, a 5-unit Cron expression is expected as input, with the following units:

  1. Minute (0-59): The minute of the hour, from 0 to 59.

  2. Hour (0-23): The hour of the day in 24-hour format, from 0 (midnight) to 23 (11 PM).

  3. Day of the Month (1-31): The day of the month, from the 1st to the 31st.

  4. Month (1-12): The month of the year, from 1 (January) to 12 (December).

  5. Day of the Week (0-6): The day of the week, from 0 (Sunday) to 6 (Saturday).

The correct order for entering a Cron expression, with a space between each unit, is:

{Minute} {Hour} {DayOfTheMonth} {Month} {DayOfTheWeek}.

Special characters

Cron expressions use special characters to define various scheduling patterns. Here are the examples of each special character:

  1. Asterisk (*) - The asterisk represents every possible value of a field.

    Eg: 0 0 * * * –> Task will run at midnight (00:00) every day of every month.

  2. Slash (/) - The slash is used to describe increments of time.

    Eg: 0 0 1 */2 * –> Task will run at midnight on the 1st day of every second month (January, March, May, etc.). The */2 in the month field specifies that the task should run every two months.

  3. Comma (,) - The comma is used to specify a list of values.

    Eg: 0 0 1,15 * * –> The task will run at midnight on the 1st and 15th of every month. The 1,15 on the day of the month field specifies that it should run on those specific days.

  4. Hyphen (-) - The hyphen is used to define a range of values.

    Eg: 0 0 * * 1-5 –> The task will run at midnight every weekday (Monday through Friday). The 1-5 in the day of the week field specifies that it should run from Monday to Friday.

  5. Last (L)—The “L” character specifies the last day of the month.

    Eg: 0 0 L * * –> This means run the task on the last day of every month at midnight (00:00)."

Invalid Cron expressions:

  1. Only 5-unit Cron expressions are accepted.
  2. Special characters ((*), (/), (,), (-)) are not allowed in the hour and minute fields.
  3. The character ‘L’ is only allowed in the Day of the Month field and must be used alone (e.g., “0 0 L * *” is valid, but “0 0 1,15,L * *” is not).
  4. Ensure there is one space between each unit; avoid extra spaces or trailing spaces.

Default Cron expressions

S No. Cron Expression Description Use Case
1. 0 0 * * * Runs daily at midnight Daily report
2. 0 8 * * 1 Runs every Monday at 8:00 AM Weekly report on Monday morning
2. 0 7 1 * * Runs on the 1st of every month at 7:00 AM Monthly report on the first day of every month
4. 0 10 1,15 * * Runs on the 1st and 15th of every month at 10:00 AM Bi-weekly report
5. 0 18 L * * Runs on the last day of every month at 6:00 PM End-of-month report
6. 0 9 1 7 * Runs on July 1st at 9:00 AM Annual mid-year report
7. 0 0 1 1-6 * Runs on the 1st of each month from January to June at midnight Semi-annual report generation
8. 30 6 */2 * * Runs every second day of the month at 6:30 AM Frequent report

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied