Scheduled Tasks
Overview
Scheduled tasks are preset tasks that execute preset automation programs or scripts at specific times. For example, querying overdue tasks and sending reminder emails every morning at 10 o'clock.
The precision of scheduled tasks is 1 minute, which means all scheduled tasks will have a delay of +(0 - 60 seconds) when executed.
ℹ️ Note
Only one scheduled task will execute at the same time. For example, if we configure a scheduled task to send emails every 5 minutes, assuming the first execution starts at 0:00 and takes 6 minutes to complete, then the automation that was supposed to execute at 0:05 will be canceled.
ℹ️ Important Information
The automation program executed by a scheduled task must not contain interactive steps.
Trigger Types
In the Informat AI Low-Code Platform, there are two main types of scheduled task triggers:
Default (Periodic Trigger): This type of scheduled task automatically triggers at preset periodic time intervals. For example, you can set a task to trigger every hour, day, or week.
Cron Expression: This type of scheduled task uses cron expressions to define complex time scheduling rules. A cron expression is a string format used to represent a schedule, allowing users to precisely define when tasks trigger at specific time points or intervals.
Examples
Default (Periodic Trigger):
- Trigger the task every day at 1 AM.
- Trigger the task every Monday morning at 8 AM.
Cron Expression:
0 0 1 * * ?: Trigger the task every day at 1 AM.0 0 8 ? * MON: Trigger the task every Monday morning at 8 AM.
Steps to Create a Scheduled Task
- Select the Scheduled Task Type: When creating a scheduled task, first select whether the task's trigger type is "Default (Periodic Trigger)" or "Cron Expression".
- Configure the Trigger Time: According to the selected type, configure the corresponding time parameters. If "Default (Periodic Trigger)" is selected, set the periodic time; if "Cron Expression" is selected, enter the cron expression.
- Set the Task Content: Define the specific operations that the scheduled task needs to execute, such as calling automation steps or scripts.
By using these two types of scheduled tasks, users can flexibly arrange and manage task execution times to meet various business needs.
Misfire Policy
In the Informat AI Low-Code Platform, the Misfire Policy for scheduled tasks refers to how the system handles situations when a scheduled task fails to trigger at the scheduled time due to some reason. Common misfire policies include:
- Execute all untriggered tasks immediately, then the trigger runs as scheduled: When a task misses its trigger time, once the system resumes operation, it immediately executes the missed tasks.
- Discard all untriggered tasks, then run as scheduled in the next scheduling cycle: When a task misses its trigger time, abandon this execution and wait for the next trigger time.
Examples
- Execute Immediately: A task is scheduled to execute every day at 1 AM, but due to system maintenance, the task does not execute at 1 AM. When the system resumes operation, it immediately executes the missed task.
- Discard All: A task is scheduled to execute every day at 1 AM, but due to system maintenance, the task does not execute at 1 AM. When the system resumes operation, it abandons this execution and waits for the next 1 AM to execute the task.
By reasonably configuring the misfire policy, you can ensure that scheduled tasks execute as expected in various situations to meet business needs.
Cron Expression Reference
A cron expression is a string divided into 7 fields by 6 spaces, where each field represents a time meaning. It is commonly used for scheduled tasks.
Cron has the following two syntax formats:
Seconds Minutes Hours DayofMonth Month DayofWeek
Seconds Minutes Hours DayofMonth Month DayofWeek YearUsually, the "Year" part can be omitted, and the first six parts are commonly used in practice.
The definitions of each cron field are shown in the following table:
| Field | Required | Values and Range | Wildcards |
|---|---|---|---|
| Seconds | Yes | 0-59 | , - * / |
| Minutes | Yes | 0-59 | , - * / |
| Hours | Yes | 0-23 | , - * / |
| Day of Month | Yes | 1-31 | , - * ? / L W |
| Month | Yes | 1-12 or JAN-DEC | , - * / |
| Day of Week | Yes | 1-7 or SUN-SAT | , - * ? / L # |
| Year | No | 1970-2099 | , - * / |
Introduction to Wildcard Meanings
,: Means execution at two or more time points. For example, if we define "8,12,35" in the "Minutes" field, it means the scheduled task executes at the 8th, 12th, and 35th minutes respectively.-: Means specifying a continuous range in a field. For example, if we define "1-6" in the "Hours" field, it means triggering once every hour between 1 and 6 o'clock, which is equivalent to "1,2,3,4,5,6".*: Means all values, which can be interpreted as "every". If set to * in the "Day" field, it means triggering every day.?: Means not specifying a value. This is used when you don't care about the value of the current field. For example, to trigger an operation on the 8th of each month but don't care about the day of the week, you can set it to "0 0 0 8 * ?"./: Means periodic triggering in a field. This symbol divides the expression in its field into two parts, where the first part is the starting value, and all fields except seconds are reduced by one unit. For example, defining "5/10" in the "Seconds" field means starting from the 5th second and executing every 10 seconds, while in the "Minutes" field, it means starting from the 5th second and executing every 10 minutes.L: Means "Last" in English and can only be used in the "Day" and "Day of Week" fields. Setting it in the "Day" field means the last day of the current month (depending on the current month, and for February, it also depends on whether it's a leap year). In the "Day of Week" field, it means Saturday, equivalent to "7" or "SAT". If a number is added before "L", it means the last occurrence of that number. For example, setting "7L" in the "Day of Week" field means "the last Saturday of the month".W: Means triggering on the nearest weekday (Monday to Friday) to the specified date. It can only be used in the "Day" field and only after a specific number. For example, setting "15W" in the "Day" field means triggering on the nearest weekday to the 15th of each month. If the 15th happens to be Saturday, it finds the nearest Friday (14th) to trigger; if the 15th is Sunday, it finds the nearest Monday (16th) to trigger. If the 15th is exactly a weekday (Monday to Friday), it triggers on that day. If it's "1W", it can only push to the next nearest weekday in the current month and cannot push to the previous month.#: Means the nth weekday of the month and can only be used in the "Day of Week" field. For example, "2#3" means the third Tuesday of the month.
Common Expression Examples
| Cron Expression | Description |
|---|---|
| 0 0 2 1 * ? | Trigger the task at 2 AM on the 1st day of every month |
| 0 15 10 ? * MON-FRI | Execute the job every weekday (Monday to Friday) at 10:15 AM |
| 0 15 10 ? 6L 2002-2006 | Execute at 10:15 AM on the last Friday of each month from 2002 to 2006 |
| 0 0 10,14,16 * * ? | Execute at 10 AM, 2 PM, and 4 PM every day |
| 0 0/30 9-17 * * ? | Execute every half hour during 9 AM to 5 PM working hours |
| 0 0 12 ? * WED | Execute at 12 PM every Wednesday |
| 0 0 12 * * ? | Trigger at 12 PM every day |
| 0 15 10 ? * * | Trigger at 10:15 AM every day |
| 0 15 10 * * ? | Trigger at 10:15 AM every day |
| 0 15 10 * * ? | Trigger at 10:15 AM every day |
| 0 15 10 * * ? 2005 | Trigger at 10:15 AM every day in 2005 |
| 0 _ 14 _ * ? | Trigger every minute from 2 PM to 2:59 PM every day |
| 0 0/5 14 * * ? | Trigger every 5 minutes from 2 PM to 2:55 PM every day |
| 0 0/5 14,18 * * ? | Trigger every 5 minutes from 2 PM to 2:55 PM and 6 PM to 6:55 PM every day |
| 0 0-5 14 * * ? | Trigger every minute from 2 PM to 2:05 PM every day |
| 0 10,44 14 ? 3 WED | Trigger at 2:10 PM and 2:44 PM every Wednesday in March |
| 0 15 10 ? * MON-FRI | Trigger at 10:15 AM every weekday (Monday to Friday) |
| 0 15 10 15 * ? | Trigger at 10:15 AM on the 15th day of every month |
| 0 15 10 L * ? | Trigger at 10:15 AM on the last day of every month |
| 0 15 10 ? * 6L | Trigger at 10:15 AM on the last Friday of every month |
| 0 15 10 ? * 6L 2002-2005 | Trigger at 10:15 AM on the last Friday of every month from 2002 to 2005 |
| 0 15 10 ? * 6#3 | Trigger at 10:15 AM on the third Friday of every month |
| 0/2 * * * * ? | Execute the task every 2 seconds |
| 0 0/2 * * * ? | Execute the task every 2 minutes |

