

AWS Data Pipeline 不再向新客户提供。的现有客户 AWS Data Pipeline 可以继续照常使用该服务。[了解详情](https://aws.amazon.com/blogs/big-data/migrate-workloads-from-aws-data-pipeline/)

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Schedule
<a name="dp-object-schedule"></a>

定义已计划事件的发生时间，例如何时活动运行。

**注意**  
如果计划的开始时间已过去，则 AWS Data Pipeline 回填您的管道并立即开始计划运行，从指定的开始时间开始。出于测试/开发目的，请使用一个相对较短的时间间隔。否则， AWS Data Pipeline 会尝试在该时间间隔内对管道的所有运行进行排队和计划。 AWS Data Pipeline 如果管道组件早于 1 天前，`scheduledStartTime`则尝试通过阻止管道激活来防止意外回填。

## 示例
<a name="schedule-example"></a>

以下是该对象类型的示例。它定义了一个每小时计划，开始时间为 2012-09-01 的 00:00:00，结束时间为 2012-10-01 的 00:00:00。第一个时段的结束时间为 2012-09-01 的 01:00:00。

```
{
  "id" : "Hourly",
  "type" : "Schedule",
  "period" : "1 hours",
  "startDateTime" : "2012-09-01T00:00:00",
  "endDateTime" : "2012-10-01T00:00:00"
}
```

以下管道将在 `FIRST_ACTIVATION_DATE_TIME` 启动，并每小时运行一次，直至 2014-04-25 的 22:00:00。

```
{
     "id": "SchedulePeriod",
     "name": "SchedulePeriod",
     "startAt": "FIRST_ACTIVATION_DATE_TIME",
     "period": "1 hours",
     "type": "Schedule",
     "endDateTime": "2014-04-25T22:00:00"
   }
```

以下管道将在 `FIRST_ACTIVATION_DATE_TIME` 启动，每小时运行一次，并在运行三次后完成。

```
{
     "id": "SchedulePeriod",
     "name": "SchedulePeriod",
     "startAt": "FIRST_ACTIVATION_DATE_TIME",
     "period": "1 hours",
     "type": "Schedule",
     "occurrences": "3"
   }
```

以下管道将在 2014-04-25 的 22:00:00 启动，每小时运行一次，并在运行三次后结束。

```
{
     "id": "SchedulePeriod",
     "name": "SchedulePeriod",
     "startDateTime": "2014-04-25T22:00:00",
     "period": "1 hours",
     "type": "Schedule",
     "occurrences": "3"
   }
```

按需 (使用默认对象)

```
{
  "name": "Default",
  "resourceRole": "DataPipelineDefaultResourceRole",
  "role": "DataPipelineDefaultRole",
  "scheduleType": "ondemand"
}
```

按需 (使用显式计划对象)

```
{
  "name": "Default",
  "resourceRole": "DataPipelineDefaultResourceRole",
  "role": "DataPipelineDefaultRole",
  "scheduleType": "ondemand"
},
{
  "name": "DefaultSchedule",
  "type": "Schedule",
  "id": "DefaultSchedule",
  "period": "ONDEMAND_PERIOD",
  "startAt": "ONDEMAND_ACTIVATION_TIME"
},
```

以下示例说明如何从默认对象继承计划、为该对象明确设置计划或通过父引用提供计划：

继承自默认对象的计划

```
{
  "objects": [
  {       
      "id": "Default",
      "failureAndRerunMode":"cascade",
      "resourceRole": "DataPipelineDefaultResourceRole",
      "role": "DataPipelineDefaultRole",
      "pipelineLogUri": "s3://myLogsbucket",
      "scheduleType": "cron",
      "schedule": {
        "ref": "DefaultSchedule"
      }
   },
   {
      "type": "Schedule",
      "id": "DefaultSchedule",
      "occurrences": "1",
      "period": "1 Day",
      "startAt": "FIRST_ACTIVATION_DATE_TIME"
    },
    { 
      "id": "A_Fresh_NewEC2Instance",
      "type": "Ec2Resource",
      "terminateAfter": "1 Hour"
    },
    {
      "id": "ShellCommandActivity_HelloWorld",
      "runsOn": {
        "ref": "A_Fresh_NewEC2Instance"
      },
      "type": "ShellCommandActivity",
      "command": "echo 'Hello World!'"
    }
  ]
}
```

对象上的显式计划

```
{
  "objects": [
  {       
      "id": "Default",
      "failureAndRerunMode":"cascade",
      "resourceRole": "DataPipelineDefaultResourceRole",
      "role": "DataPipelineDefaultRole",
      "pipelineLogUri": "s3://myLogsbucket",
      "scheduleType": "cron"
      
   },
   {
      "type": "Schedule",
      "id": "DefaultSchedule",
      "occurrences": "1",
      "period": "1 Day",
      "startAt": "FIRST_ACTIVATION_DATE_TIME"
    },
    { 
      "id": "A_Fresh_NewEC2Instance",
      "type": "Ec2Resource",
      "terminateAfter": "1 Hour"
    },
    {
      "id": "ShellCommandActivity_HelloWorld",
      "runsOn": {
        "ref": "A_Fresh_NewEC2Instance"
      },
      "schedule": {
        "ref": "DefaultSchedule"
      },
      "type": "ShellCommandActivity",
      "command": "echo 'Hello World!'"
    }
  ]
}
```

来自父引用的计划

```
{
  "objects": [
  {       
      "id": "Default",
      "failureAndRerunMode":"cascade",
      "resourceRole": "DataPipelineDefaultResourceRole",
      "role": "DataPipelineDefaultRole",
      "pipelineLogUri": "s3://myLogsbucket",
      "scheduleType": "cron"
      
   },
   {       
      "id": "parent1",
      "schedule": {
        "ref": "DefaultSchedule"
      }
      
   },
   {
      "type": "Schedule",
      "id": "DefaultSchedule",
      "occurrences": "1",
      "period": "1 Day",
      "startAt": "FIRST_ACTIVATION_DATE_TIME"
    },
    { 
      "id": "A_Fresh_NewEC2Instance",
      "type": "Ec2Resource",
      "terminateAfter": "1 Hour"
    },
    {
      "id": "ShellCommandActivity_HelloWorld",
      "runsOn": {
        "ref": "A_Fresh_NewEC2Instance"
      },
      "parent": {
        "ref": "parent1"
      },
      "type": "ShellCommandActivity",
      "command": "echo 'Hello World!'"
    }
  ]
}
```

## 语法
<a name="schedule-syntax"></a>


****  

| 必填字段 | 说明 | 槽位类型 | 
| --- | --- | --- | 
| 时段 | 管道应运行的频率。格式为“N [minutes\$1hours\$1days\$1weeks\$1months]”，其中 N 是一个数字，后跟其中一个时间说明符。例如，“15 minutes”表示每 15 分钟运行一次管道。最短时段为 15 分钟，最长时段为 3 年。 | 周期 | 

 


****  

| 所需的组 (下列选项之一是必需的) | 说明 | 槽位类型 | 
| --- | --- | --- | 
| startAt | 计划的管道运行的开始日期和时间。有效值为 FIRST\$1ACTIVATION\$1DATE\$1TIME，已弃用此值以支持创建按需管道。 | 枚举 | 
| startDateTime | 计划运行的开始日期和时间。您必须使用其中一个 startDateTime 或 startAt，但不能同时使用两者。 | DateTime | 

 


****  

| 可选字段 | 说明 | 槽位类型 | 
| --- | --- | --- | 
| endDateTime | 计划运行的结束日期和时间。日期和时间必须晚于 startDateTime 或 startAt 的值。默认行为是计划运行，直至管道关闭。 | DateTime | 
| occurrences | 在管道激活后执行管道的次数。你不能将具体值与一起使用。 endDateTime | 整数 | 
| parent | 槽将继承自的当前对象的父级。 | 引用对象，例如 “父对象”：\$1"ref”:” myBaseObject Id "\$1 | 

 


****  

| 运行时字段 | 说明 | 槽位类型 | 
| --- | --- | --- | 
| @version | 用来创建对象的管道版本。 | 字符串 | 

 


****  

| 系统字段 | 说明 | 槽位类型 | 
| --- | --- | --- | 
| @error | 用于描述格式不正确的对象的错误消息 | 字符串 | 
| @firstActivationTime | 对象创建时间。 | DateTime | 
| @pipelineId | 该对象所属的管道的 ID | 字符串 | 
| @sphere | 对象的范围指明对象在生命周期中的位置：组件对象产生实例对象，后者执行尝试对象 | 字符串 | 