Configure scheduled tasks

更新时间:
复制 MD 格式

If you have predictable load changes, you can configure scheduled tasks to provision sufficient computing resources before traffic peaks and release idle resources afterward. This helps you meet business demands while controlling costs.

Design a scaling plan

Before you create a scheduled task, design a scaling plan.

Plan 1: One-time scaling

  • Scenario

    This plan is for scenarios with a predictable, one-time change in resource demand, allowing for automated scaling.

  • Implementation

    Create a scheduled task for a specific point in time. Configure its trigger time and scaling action. For more information, see Create a scheduled task.

  • Example

    For example, if your platform runs a sales promotion on Double 11, you can schedule a task to scale out your computing resources to meet the anticipated increase in traffic and ensure service stability.

Plan 2: Recurring scaling

  • Scenario

    This plan is ideal for applications with predictable, recurring traffic patterns.

  • Implementation

    Create one scheduled task to scale out before an expected increase in usage and another to scale in when usage is expected to decrease. For more information, see Create a scheduled task.

  • Example

    For example, if your application traffic increases at 7:00 PM and decreases at 1:00 AM every day, you can create two scheduled tasks to handle these changes:

    • To handle increased traffic: Create a scheduled scale-out task to run at 7:00 PM every day. This task increases the number of replicas to improve the cluster's capacity.

    • To handle decreased traffic: Create a scheduled scale-in task to run at 1:00 AM every day. This task reduces the number of replicas to improve resource utilization and lower costs.

Access the scheduled tasks page

You can manage all scheduled tasks for a scaling group on its Scheduled Tasks page. Follow these steps to access the page.

Procedure

  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 target scaling group and click its name to go to the details page.

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

Create a scheduled task

After you design a scaling plan, follow these steps to create a scheduled task to implement it.

Important

The number of scheduled tasks that you can create per account is limited. The quota in a specific region depends on your Auto Scaling usage. To view your quota, go to Quota Center.

  1. On the Scheduled Tasks tab, click Create Scheduled Task. In the Create Scheduled Task dialog box, configure the following parameters.

    1. Configure the Basic Information for the task.

      Parameter

      Description

      Task Name

      Enter a name for the scheduled task.

      The name must be 2 to 64 characters long and 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 long. Use the description to record the task's purpose for future reference.

    2. Configure the Execution Time for the task.

      Parameter

      Description

      Executed At

      The time when the scheduled task is triggered.

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

      • If a recurrence is set, this time serves as the execution time for the recurring task.

      Important

      The execution time must be within 90 days of the task's creation or modification date. Otherwise, the task will not run.

      Retry Interval (Seconds)

      Optional. The period in which Auto Scaling retries a failed task. Valid values: 0 to 1800 (30 minutes).

      Recurrence

      Optional. The recurring schedule for the task. You can select Not Set, By Day, By Week, By Month, or Cron Expression.

      Expired At

      This parameter appears if you set Recurrence to By Day, By Week, By Month, or Cron Expression. Specify when the recurring task ends. The end time must be later than the first execution time.

      Cron expressions for scheduled tasks

      When you configure a scheduled task in the Auto Scaling console, you can select Cron Expression for the Recurrence parameter.

      A cron expression is a string that specifies a schedule. It consists of space-separated fields. Auto Scaling supports cron expressions with five fields in the format X X X X X, where X is a placeholder for a field. The fields represent minute, hour, day of the month, month, and day of the week, in that order. Each field can contain a specific value or a special character with a logical meaning.

      When you configure a cron expression, note the following:

      • Cron expressions use the UTC+0 time zone. You must convert your local time to UTC+0. For example, because the China time zone is UTC+8, to run a task at 20:00 daily, you must subtract 8 hours. The resulting UTC time is 12:00, so the cron expression is 0 12 * * ?.

      • A single cron-based scheduled task can run at most once every five minutes.

      • The first execution triggered by the cron expression must occur before the recurrence end time. Otherwise, a parameter error is returned.

      Table 1. Fields and values

      Field

      Required

      Valid values

      Special characters

      Minute

      Yes

      0-59

      , - / *

      Hour

      Yes

      0-23

      , - / *

      Day of month

      Yes

      1-31

      , - / * ? L W

      Month

      Yes

      1-12

      , - / *

      Day of week

      Yes

      1-7, where 7 represents Sunday.

      , - * ? / L #

      Table 2. Special characters

      Character

      Description

      Example

      *

      All possible values in the field.

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

      ,

      A list of enumerated values.

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

      -

      A range of values.

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

      /

      Specifies increments.

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

      ?

      Indicates no specific value. This character is supported only in the Day of month and Day of week fields.

      Note

      To avoid conflicts, if you specify a value for either the Day of month or Day of week field, you must use a ? in the other.

      In the Day of month field, ? means no specific day is designated. In the Day of week field, ? means no specific day of the week is designated. For example, the UTC expression 15 10 15 * ? means the task runs at 10:15 on the 15th of every month, regardless of the day of the week.

      L

      The last day. This character is supported only in the Day of month and Day of week fields.

      Note

      If you use the L character, do not specify a list or a range of values. Otherwise, logical conflicts may occur.

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

      • If L is preceded by a value, it has a specific meaning. For example, 6L in the Day of week field means the last Saturday of the month.

      W

      The nearest weekday (Monday to Friday) to a specified day. The W character finds the nearest weekday but does not cross month boundaries. The combination LW indicates the last weekday of a specified month.

      In the Day of month field, for 5W, if the 5th is a Saturday, the task is triggered on the nearest weekday, which is Friday the 4th. If the 5th is a Sunday, the task is triggered on Monday the 6th. If the 5th is a weekday, the task is triggered on the 5th.

      #

      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 the month.

      Table 3. Examples (UTC+8)

      The following table provides examples of cron expressions for the UTC+8 time zone. Remember to convert your local time to UTC+0 when you configure cron expressions.

      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 daily at 18:00, 22:00, and 00:00 (the following day).

      15 10 15 * ?

      Runs the task at 18:15 on the 15th 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.

    3. Configure the Action to Execute for the scheduled task.

      Note

      Differences between the two scaling methods:

      • Select Existing Scaling Rule: Allows you to add or remove N instances, add or remove N% of instances, or adjust the total number of instances to N.

      • Set Number of Instances in Scaling Group: Allows you to modify the Maximum/Minimum Instances settings. If an expected number of instances is enabled for the scaling group, you can also set the expected number of instances.

      Scaling rule

      Parameter

      Description

      Scaling Method

      Set this to Select an existing rule. You must then select an existing simple scaling rule from your scaling group.

      Simple Scaling Rule

      This parameter appears when Scaling Method is set to Select Existing Scaling Rule. Select an existing simple scaling rule. For more information, see Manage scaling rules or CreateScalingRule.

      Instance count

      Parameter

      Description

      Scaling Method

      Set this to Configure the number of instances in a scaling group. You must then enter a value for Maximum Instances, Minimum Instances, or Expected Number of Instances.

      Maximum Instances

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

      Minimum Number of Instances

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

      Expected Number of Instances

      The scaling group initiates scaling activities to ensure that the number of running instances matches this value.

  2. After you confirm the configuration, click OK.

Disable a scheduled task

Scheduled tasks are enabled by default after creation. You can disable a task if it is temporarily not needed. You can disable a task only if it is in the Enable state.

Procedure

On the Scheduled Tasks page, find the task to disable and click Disable in the Actions column.

Enable a scheduled task

To resume a disabled task, you can enable it. You can enable a task only if it is in the Disable state.

Procedure

On the Scheduled Tasks page, find the task to enable and click Enable in the Actions column.

Modify a scheduled task

If a scheduled task no longer meets your requirements, you can modify it.

Procedure

On the Scheduled Tasks page, find the task to modify and click Modify in the Actions column. For parameter descriptions, see Create a scheduled task.

Delete a scheduled task

If you no longer need a scheduled task, you can delete it.

Procedure

On the Scheduled Tasks page, find the task to delete and click Delete in the Actions column.

Related APIs