This topic describes how to create a scheduled task to scale computing resources in response to expected business changes in the future. Scheduled tasks allow the system to automatically obtain sufficient computing resources before business peaks occur and release idle computing resources after the business peaks end.
Background information
A scheduled task is a preconfigured task that executes a specified scaling rule at a specified time. When the specified time arrives, the scheduled task automatically scales computing resources. This allows you to reduce costs and meet business requirements.
To create a scheduled task, configure the following parameters based on your business requirements:
- Executed At: Specify the time at which you want the scheduled task to be executed.
If no value is specified for the Recurrence parameter, the scheduled task is executed
once at the time specified by the Executed At parameter. If a value is specified for
the Recurrence parameter, the scheduled task is executed once at the time specified
by the Executed At parameter and is repeatedly executed based on the cycle specified
by the Recurrence parameter.
Notice Do not specify a time later than 90 days from the date on which the scheduled task is created or modified. Otherwise, the scheduled task cannot take effect.
- Scaling Group: Select an existing scaling group. For more information, see Overview.
- Scaling Method: You can set the Scaling Method parameter to Select Existing Scaling Rule or Configure Number of Instances in Scaling Group.
- Simple Scaling Rule: This parameter is available only if you set the Scaling Method parameter to Select Existing Scaling Rule. Select an existing scaling rule based on your business requirements.
- Retry Interval (Seconds): You can specify a retry interval at which a scheduled task is retried if the scheduled task fails. This ensures that the scheduled task can run as expected. If multiple scheduled tasks need to be executed within the same minute, Auto Scaling executes the most recently created scheduled task.
- Recurrence: You can set the Recurrence parameter to Not Set, By Day, By Week, or By
Month. If you have complex business requirements, you can also set the Recurrence
parameter to Cron Expression. For information about the cron expressions, see Cron expression.
Note You cannot change the value of the Recurrence parameter to Not Set.
Procedure
- Log on to the Auto Scaling console.
- In the left-side navigation pane, choose .
- In the top navigation bar, select a region.
- Click Create Scheduled Task.
- In the dialog box that appears, configure the parameters for the scheduled task.
- Click OK.
Cron expression
A cron expression is a string that represents a schedule. The string consists of multiple
fields that are separated by spaces and describe individual details of the schedule.
A scheduled task supports a cron expression that consists of five fields in the X X X X X
format. X
specifies a placeholder for a field. Each field in a cron expression represents minutes,
hours, day of month, month, and day of week in sequence. Each field can be a definite
value or a special character that has logical meaning.
When you configure a cron expression for a scheduled task, take note of the following items:
- Cron expressions are in UTC+0. When you configure a cron expression, you must convert
the local time to UTC+0. For example, the time in China is in UTC+8. If you want to
execute your scheduled task at 20:00 every day in China, you must subtract 8 hours
from the scheduled execution time. In this case, you must set the cron expression
to
0 12 * * ?
. - A scheduled task that has a specified cron expression can be executed only once per hour.
- The time at which a scheduled task that has a specified cron expression is first executed must be earlier than the time at which the cycle specified by the Recurrence parameter for the scheduled task to be executed expires. Otherwise, an error is reported.
Field | Required | Valid value | Special character |
---|---|---|---|
Minute | Yes | 0~59 | , - / * |
Hour | Yes | 0~23 | , - / * |
Day | Yes | 1~31 | , - / * ? L W |
Month | Yes | 1~12 | , - / * |
Week | Yes | 1-7. The value for Sunday is 7. | , - * ? / L # |
Special character | Description | Example |
---|---|---|
* |
All valid field values | In the Month field, an asterisk (* ) specifies every month. In the Week field, an asterisk (* ) specifies every day of a week.
|
, |
Enumerated values | In the Minute field, 5,20 specifies the 5th to 20th minute.
|
- |
Range values | In the Minute field, 5-20 specifies that the task is triggered once every minute from the 5th to 20th minute.
|
/ |
Increments | In the Minute field, 0/15 specifies every 15 minutes starting from the zeroth minute. 3/20 specifies every 20 minutes starting from the third minute.
|
? |
Unspecified. Only the Day and Week fields support this character.
Note If one of the Day and Week fields is specified, the other field must be set to a question
mark (
? ) to prevent computing conflicts.
|
In the Day field, ? specifies that no specific day of the month is specified. In the Week field, ? specifies that no specific day of the week is specified. For example, 15 10 15 * ? in UTC+0 specifies that the scheduled task is executed at 10:15 on the 15th day of
each month, regardless of the day of the week.
|
L |
L, the first letter of Last, specifies the last day of a specific period. Only the
Day and Week fields support this character.
Note To prevent logic errors, do not specify a list or range when you use the
L character.
|
|
W |
The weekday that is nearest to the specified day of the month. The weekday that the
W character specifies is in the same month as the specified day of the month. LW specifies the last weekday of the specified month.
|
If 5W is specified in the Day field and the 5th day of the month falls on Saturday, the
task is triggered on Friday, which is the 4th day of the month. If the 5th day of
the month falls on Sunday, the scheduled task is triggered on Monday, which is the
6th day of the month. If the 5th day of the month falls on a weekday, the scheduled
task is triggered on the 5th day of the month.
|
# |
A specific day of a specific week every month. Only the Week field supports this character. Valid values: 1 to 5. | In the Week field, 4#2 specifies the second Thursday of a month.
|
Example | Description |
---|---|
15 10 ? * * |
Executes the scheduled task at 10:15 every day. |
15 9 * * * |
Executes the scheduled task at 9:15 every day. |
0 12 * * ? |
Executes the scheduled task at 12:00 every day. |
0 10,14,16 * * ? |
Executes the scheduled task at 10:00, 14:00, and 16:00 every day. |
15 10 15 * ? |
Executes the scheduled task at 10:15 on the 15th day of every month. |
15 10 L * ? |
Executes the scheduled task at 10:15 on the last day of every month. |
15 10 ? * 6L |
Executes the scheduled task at 10:15 on the last Saturday of every month. |
15 10 ? * 6#3 |
Executes the scheduled task at 10:15 on the third Saturday of every month. |