

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 嘗試將管道的所有執行排入佇列並排程在該間隔內。如果管道元件`scheduledStartTime`早於 1 天，則 AWS Data Pipeline 嘗試封鎖管道啟用，以防止意外回填。

## 範例
<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"
   }
```

使用 Default 物件的隨需

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

使用明確 Schedule 物件的隨需

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

下列範例會示範如何從預設物件繼承 Schedule，針對該物件明確設定，或是由父參考明確給予。

從 Default 物件繼承的 Schedule

```
{
  "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>


****  

| 必要欄位 | Description | 槽類型 | 
| --- | --- | --- | 
| period | 管道應有的執行頻率。格式為 "N [minutes\$1hours\$1days\$1weeks\$1months]"，其中 N 是數字，後接其中一個時間指定元。例如 "15 minutes"，表示每 15 分鐘執行一次管道。最短期間為 15 分鐘，而最長期間為 3 年。 | Period | 

 


****  

| 必要的群組 (下列其中之一為必要) | Description | 槽類型 | 
| --- | --- | --- | 
| startAt | 開始執行排程管道的日期和時間。有效值為 FIRST\$1ACTIVATION\$1DATE\$1TIME，若要建立隨需管道則可將其移除。 | 列舉 | 
| startDateTime | 開始執行排程的日期和時間。您必須使用 startDateTime 或 startAt，但不能同時使用兩者。 | DateTime | 

 


****  

| 選用欄位 | Description | 槽類型 | 
| --- | --- | --- | 
| endDateTime | 結束執行排程的日期和時間。此日期和時間必須晚於 startDateTime 或 startAt 值。預設行為是排程執行直到管道關閉為止。 | DateTime | 
| occurrences | 啟動管道之後的管道執行次數。您不能搭配使用 occurrences 與 endDateTime。 | Integer | 
| parent | 目前物件的父系，其插槽會被繼承。 | 參考物件，例如 "parent":\$1"ref":"myBaseObjectId"\$1 | 

 


****  

| 執行時間欄位 | Description | 槽類型 | 
| --- | --- | --- | 
| @version | 建立物件使用的管道版本。 | String | 

 


****  

| 系統欄位 | Description | 槽類型 | 
| --- | --- | --- | 
| @error | 描述格式錯誤物件的錯誤 | String | 
| @firstActivationTime | 建立物件的時間。 | DateTime | 
| @pipelineId | 此物件所屬管道的 ID | String | 
| @sphere | 物件範圍代表其在生命週期中的位置：Component 物件會引發執行 Attempt 物件的 Instance 物件 | String | 