Configure scheduled tasks

Updated at:

If changes in workload are predictable, you can configure scheduled tasks to prepare sufficient computing resources before peak traffic arrives, or promptly release idle computing resources after the peak, meeting business needs while controlling costs.

Design a scheduled scaling plan

Decide when the task must run and what it must change before you create it.

Plan 1: scale once at a specific point in time

  • When to use — You expect a sudden increase or decrease in resource demand at a specific point in the future, and you want the scaling action to run automatically at that time.

  • How to implement — Create a scheduled task for that point in time. Set the trigger time, and specify the scaling action that the task performs after it is triggered. For the full procedure, see Create a scheduled task in this topic.

  • Example — If your platform runs a promotional campaign on Double 11, schedule a scale-out of your compute resources on that day to meet the actual resource demand and keep services running stably.

Plan 2: scale on a recurring schedule

  • When to use — Your workload fluctuates in a regular pattern. That is, the resource usage of your scaling group rises and falls at predictable times.

  • How to implement — At times when resource utilization in the business cluster increases, trigger scaling out through scheduled tasks. Conversely, when resource utilization decreases, trigger scaling in through scheduled tasks. For the full procedure, see Create a scheduled task in this topic.

  • Example — Traffic to your workload increases at 7:00 PM and decreases at 1:00 AM every day. To address changes in business access demand, you can set the following two scheduled tasks.

    • Configure a scheduled scale-out task for 7:00 PM that increases the number of instances in the scaling group to add capacity.

    • Configure a scheduled scale-in task for 1:00 AM that decreases the number of instances to improve resource utilization and reduce unnecessary costs.

Go to the scheduled task list

You manage all scheduled tasks of a scaling group from the Scheduled Tasks list. To open the list, perform the following steps.

  1. Log on to the Auto Scaling console.

  2. In the left-side navigation pane, click Scaling Groups.

  3. In the top navigation bar, select a region.

  4. On the Scaling Groups page, find the scaling group that you want to manage and click the scaling group name to go to the scaling group details page.

  5. Click the Scaling Rules and Tasks tab and find the Scheduled Tasks list.

Create a scheduled task

After you design your scheduled scaling plan, create a scheduled task that implements it. Go to the Scheduled Tasks list of the scaling group, and then perform the following steps.

Important

The number of scheduled tasks that can be created under one account is limited. The number of scheduled tasks in a single region depends on the usage of Auto Scaling. Please go to the Quota Center to view the quota value.

  1. Click Create Scheduled Task. In the Create Scheduled Task dialog box that appears, configure the parameters as prompted and as described in the following tables.

  2. Configure the Basic Information of the scheduled task.

    Parameter

    Description

    Task Name

    Enter a name for the scheduled task. The name must be 2 to 64 characters in length and must start with a letter, a digit, or a Chinese character. It can contain periods (.), underscores (_), and hyphens (-).

    Description

    Optional. Enter a description for the scheduled task. The description must be 2 to 200 characters in length. Use the description to record information such as the purpose and role of the scheduled task for later reference.

  3. Configure the Execution Time of the scheduled task.

    Parameter

    Description

    Executed At

    Enter the time when the scheduled task is triggered.

    • If no recurrence is configured, the task runs once at the specified date and time.

    • If a recurrence is configured, the point in time specified by this parameter is used by default as the execution time of the recurring task.

    Important

    Do not specify a time later than 90 days from the day on which the task is created or modified. Otherwise, the scheduled task cannot take effect.

    Retry Interval (Seconds)

    Optional. The length of the retry window, in seconds. Valid values: 0 to 1800 (30 minutes). If the scaling action is not triggered at the execution time, Auto Scaling keeps trying to run the scheduled task until the retry window expires.

    Recurrence

    Optional. Select the period at which the scheduled task runs repeatedly. Valid values: Not Set, By Day, By Week, By Month, or a cron expression.

    Expired At

    This parameter appears only when the recurrence is set to By Day, By Week, By Month, or a cron expression. Enter the end time of the recurrence for the scheduled task. The end time of the recurrence must be later than the first execution time of the task.

    Cron expression description for scheduled tasks.

    When configuring the Recurrence parameter for a scheduled task in the Auto Scaling console, you can use a Cron expression.

    A Cron expression is a string with time-related meaning. Each character with time meaning is called a field, and the fields are separated by spaces. Auto Scaling scheduled tasks support Cron expressions with 5 fields, in the format X X X X X, where X is a placeholder for a field. In a Cron expression, each field represents minutes, hours, day, month, and day of week in order. Each field can be a specific value or a special character with logical meaning.

    When configuring a Cron expression for a scheduled task, note the following:

    • Cron expressions use the UTC+0 time zone. When configuring the expression, you need to convert your local time to UTC+0 time. For example, China uses UTC+8. If you plan to run a task at 20:00 China time every day, you need to subtract 8 hours and set the Cron expression to 0 12 * * ?.

    • A single Cron scheduled task can run only once every five minutes.

    • Make sure the first execution time of the Cron expression is earlier than the scheduled task’s repeat end time; otherwise, a parameter error will be returned.

    Fields in a cron expression

    Field

    Required

    Valid values

    Special characters

    Minute

    Yes

    0 to 59

    , - / *

    Hour

    Yes

    0 to 23

    , - / *

    Day

    Yes

    1 to 31

    , - / * ? L W

    Month

    Yes

    1 to 12

    , - / *

    Day of week

    Yes

    1 to 7, where Sunday is 7

    , - * ? / L #

    Special characters in a cron expression

    Special character

    Description

    Example

    *

    All possible values in the field.

    In the Month field, * indicates every month. In the Day of week field, * indicates every day of the week.

    ,

    Lists enumerated values.

    In the Minute field, 5,20 indicates the 5th minute and the 20th minute.

    -

    Indicates a range of values.

    In the Minute field, 5-20 indicates every minute from the 5th minute to the 20th minute.

    /

    Specifies an increment of a value.

    In the Minute field, 0/15 indicates every 15 minutes starting from minute 0, and 3/20 indicates every 20 minutes starting from minute 3.

    ?

    Specifies no value. This character is supported only in the Day field and the Day of week field.

    Note

    After a value is specified for either the Day field or the Day of week field, you must set the value of the other field to ? to avoid calculation conflicts.

    In the Day field, ? indicates that no specific day is specified. In the Day of week field, ? indicates that no specific day of the week is specified. For example, in the UTC+0 time zone, 15 10 15 * ? indicates that the task runs at 10:15 on the 15th day of every month, regardless of the day of the week on which the 15th day falls.

    L

    Indicates the last day. This character is supported only in the Day field and the Day of week field.

    Note

    When you specify the L character, avoid specifying a list or a range. Otherwise, logical issues occur.

    • In the Day field, L indicates the last day of a month. In the Day of week field, L indicates the last day of a week.

    • If L is preceded by specific content, for example, 6L in the Day of week field, it indicates the last Saturday of the month.

    W

    A valid workday other than a weekend. The event is triggered on the valid workday closest to the specified day. When the W character looks for the closest valid workday, it does not cross the current month. When the characters LW are used together, they indicate the last workday of the specified month.

    For 5W in the Day field, if the 5th day is a Saturday, the task is triggered on the closest workday, Friday the 4th day. If the 5th day is a Sunday, the task is triggered on the closest workday, Monday the 6th day. If the 5th day falls on a day from Monday to Friday, the task is triggered on the 5th day.

    #

    Specifies the Nth day of the week in a month. This character is supported only in the Day of week field. Valid values: 1 to 5.

    In the Day of week field, 4#2 indicates the second Thursday of a month.

    Examples (UTC+8)

    The following table describes what each cron expression example means as a local time in the UTC+8 time zone. Because cron expressions are evaluated in the UTC+0 time zone, remember to convert your local time to UTC+0 when you set an expression.

    Example

    Description

    15 10 ? * *

    Runs the task at 18:15 every day.

    15 9 * * *

    Runs the task at 17:15 every day.

    0 12 * * ?

    Runs the task at 20:00 every day.

    0 10,14,16 * * ?

    Runs the task at 18:00 and 22:00 every day, and at 00:00 on the following day.

    15 10 15 * ?

    Runs the task at 18:15 on the 15th day of every month.

    15 10 L * ?

    Runs the task at 18:15 on the last day of every month.

    15 10 ? * 6L

    Runs the task at 18:15 on the last Saturday of every month.

    15 10 ? * 6#3

    Runs the task at 18:15 on the third Saturday of every month.

  4. Configure the Action to Execute for the scheduled task, that is, the scaling method that the task uses. Choose the scaling method based on the result that you want:

    • Adjust capacity relative to the current capacity, or to a value defined in a rule — Select Select an existing rule. The task runs a simple scaling rule that you configured to Add/Remove N instances, Add/Remove N% of instances, or Adjust to N instances.

    • Change the capacity boundaries or the target capacity of the scaling group — Select Configure the number of instances in a scaling group. The task modifies the Maximum/Minimum Instances of the scaling group. If the expected number of instances is enabled for the scaling group, the task can also set the Expected Number of Instances.

    Select an existing scaling rule (simple rule)

    Parameter

    Description

    Scaling Method

    Select an existing rule: After you select this scaling method, also select an existing scaling rule (simple rule) in the scaling group.

    Simple Scaling Rule

    This parameter appears only when the scaling method is Select an existing rule. Select a scaling rule (simple rule) that you created in the scaling group. For more information, see Configure scaling rules.

    Set the number of instances in the scaling group (directly modify the instance count of the scaling group)

    Parameter

    Description

    Scaling Method

    Configure the number of instances in a scaling group: After you select this scaling method, also enter the maximum number of instances, the minimum number of instances, or the expected number of instances.

    Maximum Instances

    The upper limit for the number of instances in the scaling group.

    Minimum Number of Instances

    The lower limit for the number of instances in the scaling group.

    Expected Number of Instances

    The scaling group adjusts the actual number of instances through scaling activities so that the actual number of instances in the scaling group equals the expected number of instances.

  5. After you confirm the configuration, click OK to complete the creation of the scheduled task.

Manage existing scheduled tasks

Disable, re-enable, modify, and delete scheduled tasks from the Scheduled Tasks list of the scaling group. Find the scheduled task that you want to manage, click the corresponding button in the Actions column, and then complete the operation as prompted.

Operation

Button

Description

Disable a scheduled task

Disable

A scheduled task is enabled after you create it. Disable the task if you do not need it to trigger a scaling activity for the time being. Available only for a task in the Enabled state.

Re-enable a scheduled task

Enable

Enable a disabled task again to continue using it at the specified time. Available only for a task in the Disabled state.

Modify a scheduled task

Modify

Change the configuration of a scheduled task that no longer meets your requirements. For descriptions of the parameters, see Create a scheduled task in this topic.

Delete a scheduled task

Delete

Delete a scheduled task that is no longer in use.

References