文档

定时触发器ACS::TimerTrigger

更新时间:

用途

用于需要定时的运维场景。启动执行后,OOS即将执行置于等待状态,直到指定的时刻才开始后续的任务。任务完成以后重新进入到等待状态。

限制

触发器有如下限制:

  • 一个模版只允许有一个触发器动作。

  • 触发器动作的任务必须定义在模版Tasks中的第一个任务。

  • 被嵌套的模版(子模版)中不允许有触发器动作。

语法

  • YAML格式

Tasks:
  - Name: timerTask # 任务名称
    Action: ACS::TimerTrigger
    Properties:
      Type: cron # 必填,时间类型,可选cron、at或rate。
      Expression: '0 * * ? * *' # 必填,cron表达式(cron默认是按UTC时间计算)、日期时间表达式或rate。
          TimeZone: 'Asia/Shanghai' #  选填,所选时间对应的时区,默认为UTC。
      EndDate: '2020-12-29T09:19:30Z' # 必填,终止时间(UTC时间,格式为YYYY-MM-DD或YYYY-MM-DDThh:mm:ssZ)。
  • JSON格式(请参考YAML注释说明)

{
  "Tasks": [
    {
      "Name": "timerTask",
      "Action": "ACS::TimerTrigger",
      "Properties": {
        "Type": "cron",
        "Expression": "0 * * ? * *",
        "EndDate": "2020-12-29T09:19:30Z",
        "TimeZone": "Asia/Shanghai"
      }
    }
  ]
}

流程图

流程图说明如下:

  • 用户创建执行后,父执行即进入等待(Waiting)状态。

  • 到达指定时间后,父执行即进入执行中(Running)状态。同时,父执行自动创建一个子执行,使用同样的模板,同样的参数,但是跳过触发器任务(Trigger Task)直接执行后续任务。

  • 等到子执行完成后,如图中的成功(Success)状态,也可以是失败(Failed)或取消状态(Cancelled),父执行重新进入等待(Waiting)状态,等待到达下次指定时间,然后重复上述步骤。

  • 到达指定的终止时间后,父执行停止等待,完成执行并标记为成功(Success)。

  • 用户可以像取消普通执行一样取消父执行或子执行,被取消的执行状态为取消(Cancelled)。

示例

cron类型

  • YAML格式:

FormatVersion: OOS-2019-06-01
Description: Schedule to reboot ECS instances.
Tasks:
  - Name: timer
    Action: ACS::TimerTrigger
    Properties:
      Type: cron
      Expression: 5 minute
      EndDate: 2020-12-20T00:00:00Z
  - Name: rebootInstance
    Action: ACS::ECS::RebootInstance
    Properties:
      InstanceId: "i-xxxxx"
  • JSON格式:

{
  "FormatVersion": "OOS-2019-06-01",
  "Description": "Schedule to reboot ECS instances.",
  "Tasks": [
    {
      "Name": "timer",
      "Action": "ACS::TimerTrigger",
      "Properties": {
        "Type": "cron",
        "Expression": "5 minute",
        "EndDate": "2020-12-20 00:00:00 UTC"
      }
    },
    {
      "Name": "rebootInstance",
      "Action": "ACS::ECS::RebootInstance",
      "Properties": {
        "InstanceId": "i-xxxxx"
      }
    }
  ]
}

at类型

  • YAML格式:

FormatVersion: OOS-2019-06-01
Description: Schedule to reboot ECS instances.
Tasks:
  - Name: timer
    Action: ACS::TimerTrigger
    Properties:
      Type: at
      Expression: '2020-02-29T09:17:35Z'
      EndDate: 2020-12-20T00:00:00Z
  - Name: rebootInstance
    Action: ACS::ECS::RebootInstance
    Properties:
      InstanceId: "i-xxxxx"
  • JSON格式:

{
  "FormatVersion": "OOS-2019-06-01",
  "Description": "Schedule to reboot ECS instances.",
  "Tasks": [
    {
      "Name": "timer",
      "Action": "ACS::TimerTrigger",
      "Properties": {
        "Type": "at",
        "Expression": "2020-02-29T09:17:35Z",
        "EndDate": "2020-12-20T00:00:00.000Z"
      }
    },
    {
      "Name": "rebootInstance",
      "Action": "ACS::ECS::RebootInstance",
      "Properties": {
        "InstanceId": "i-xxxxx"
      }
    }
  ]
}
  • 本页导读 (0)
文档反馈