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.

Note You can create only a limited number of scheduled tasks within an Alibaba Cloud account. For more information, see Limits.

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

  1. Log on to the Auto Scaling console.
  2. In the left-side navigation pane, choose Scaling Tasks > Scheduled Tasks.
  3. In the top navigation bar, select a region.
  4. Click Create Scheduled Task.
  5. In the dialog box that appears, configure the parameters for the scheduled task.
    1. Enter a name for the scheduled task.
      The name must be 2 to 64 characters in length and can contain letters, digits, periods (.), underscores (_), and hyphens (-). The name must start with a letter or digit.
    2. Optional:Enter a description for the scheduled task.
      The description must be 2 to 200 characters in length and can contain information such as the purpose and feature of the scheduled task.
    3. Specify the time at which you want the scheduled task to be executed.
      The scheduled task is triggered when the specified time arrives.
    4. Select a scaling group.
    5. Specify a scaling method.
      • Select Existing Scaling Rule: Select an existing scaling rule in the scaling group. You can search for scaling rules by name. The scaling rule that you select is executed when the scheduled task is triggered.
        Note Scheduled tasks can execute only simple scaling rules.
      • Configure Number of Instances in Scaling Group: Enter the minimum, maximum, and expected numbers of instances in the scaling group. When the scheduled task is triggered, the configurations that you specify overwrite the configurations of the scaling group.
        Note If the Expected Number of Instances feature is disabled when you create a scaling group, you can specify only the minimum and maximum numbers of instances in the scaling group.
    6. Optional:Specify a retry interval.
      Valid values: 0 to 21600. Unit: seconds. If a scaling activity fails to be executed at the specified time, Auto Scaling executes the scheduled task again within the period of time that is specified by the Retry Interval (Seconds) parameter.
    7. Optional:Configure the recurrence period.
      Specify a cycle for the scheduled task to be executed. You must also specify the time at which the scheduled task expires. The time at which the scheduled task expires must be later than the time at which the scheduled task is first executed.
  6. 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.
Table 1. Field values
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 #
Table 2. Special characters
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.
  • In the Day field, L specifies the last day of a month. In the Week field, L specifies the last day of a week.
  • L can be preceded by a value. For example, 6L in the Week field specifies the last Saturday of a month.
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.
Table 3. Examples

The following table provides examples of cron expressions in UTC+0. These cron expressions have different meanings. When you configure a cron expression, you must convert the local time to UTC+0.

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.