Azure 计划程序的概念、术语和实体Concepts, terminology, and entities in Azure Scheduler

Important

Azure 逻辑应用将替换即将停用的 Azure 计划程序。Azure Logic Apps is replacing Azure Scheduler, which is being retired. 若要继续使用在计划程序中设置的作业,请尽快迁移到 Azure 逻辑应用To continue working with the jobs that you set up in Scheduler, please migrate to Azure Logic Apps as soon as possible.

实体层次结构Entity hierarchy

Azure 计划程序 REST API 公开并使用以下主要实体或资源:The Azure Scheduler REST API exposes and uses these main entities, or resources:

实体Entity 说明Description
作业Job 通过用于执行的简单或复杂策略定义单个定期操作。Defines a single recurring action with simple or complex strategies for execution. 操作可以包括 HTTP、存储队列、服务总线队列或服务总线主题请求。Actions might include HTTP, Storage queue, Service Bus queue, or Service Bus topic requests.
作业集合Job collection 包含一组作业,并且维护集合内各作业共享的设置、配额和限制。Contains a group of jobs and maintains settings, quotas, and throttles that are shared by jobs in the collection. 作为 Azure 订阅所有者,你可以创建作业集合,并根据使用情况或应用程序边界将作业分组。As an Azure subscription owner, you can create job collections and group jobs together based on their usage or application boundaries. 作业集合具有以下特性:A job collection has these attributes:

- 限制在一个区域。- Constrained to one region.
- 可以强制执行配额,以便限制集合中所有作业的使用。- Lets you enforce quotas so you can constrain usage for all jobs in a collection.
- 配额包括 MaxJobs 和 MaxRecurrence.- Quotas include MaxJobs and MaxRecurrence.

作业历史记录Job history 描述作业执行的详细信息,例如状态和任何响应详细信息。Describes details for a job execution, for example, status and any response details.

实体管理Entity management

计划程序 REST API 在高级别公开这些操作以管理实体。At a high-level, the Scheduler REST API exposes these operations for managing entities.

作业管理Job management

支持创建和编辑作业的操作。Supports operations for creating and editing jobs. 所有作业都必须属于某一现有作业集合,因此没有显式创建。All jobs must belong to an existing job collection, so there's no implicit creation. 有关详细信息,请参阅计划程序 REST API - 作业For more information, see Scheduler REST API - Jobs. 下面是这些操作的 URI 地址:Here's the URI address for these operations:

https://management.chinacloudapi.cn/subscriptions/{subscriptionID}/resourceGroups/{resourceGroupName}/providers/Microsoft.Scheduler/jobCollections/{jobCollectionName}/jobs/{jobName}

作业集合管理Job collection management

支持创建和编辑作业和作业集合(映射到配额和共享设置)的操作。Supports operations for creating and editing jobs and job collections, which map to quotas and shared settings. 例如,配额指定最大作业数量和最小重复周期间隔。For example, quotas specify the maximum number of jobs and smallest recurrence interval. 有关详细信息,请参阅计划程序 REST API - 作业集合For more information, see Scheduler REST API - Job Collections. 下面是这些操作的 URI 地址:Here's the URI address for these operations:

https://management.chinacloudapi.cn/subscriptions/{subscriptionID}/resourceGroups/{resourceGroupName}/providers/Microsoft.Scheduler/jobCollections/{jobCollectionName}

作业历史记录管理Job history management

支持用于获取 60 天的作业执行历史记录(例如,作业已用时间和作业执行结果)的 GET 操作。Supports the GET operation for fetching 60 days of job execution history, for example, job elapsed time and job execution results. 包含基于状态进行筛选的查询字符串参数支持。Includes query string parameter support for filtering based on state and status. 有关详细信息,请参阅计划程序 REST API - 作业 - 列出作业历史记录For more information, see Scheduler REST API - Jobs - List Job History. 下面是该操作的 URI 地址:Here's the URI address for this operation:

https://management.chinacloudapi.cn/subscriptions/{subscriptionID}/resourceGroups/{resourceGroupName}/providers/Microsoft.Scheduler/jobCollections/{jobCollectionName}/jobs/{jobName}/history

作业类型Job types

Azure 计划程序支持多个作业类型:Azure Scheduler supports multiple job types:

  • 当你拥有现有服务或工作负载的终结点时的 HTTP 作业(包括支持 SSL 的 HTTPS 作业)HTTP jobs, including HTTPS jobs that support SSL, for when you have the endpoint for an existing service or workload
  • 针对使用存储队列的工作负载的存储队列作业,例如将消息发布到存储队列Storage queue jobs for workloads that use Storage queues, such as posting messages to Storage queues
  • 针对使用服务总线队列的工作负载的服务总线队列作业Service Bus queue jobs for workloads that use Service Bus queues
  • 针对使用服务总线主题的工作负载的服务总线主题作业Service Bus topic jobs for workloads that use Service Bus topics

作业定义Job definition

在高级别,计划程序作业包含以下基本部分:At the high level, a Scheduler job has these basic parts:

  • 在引发作业计时器时运行的操作The action that runs when the job timer fires
  • 可选:运行作业的时间Optional: The time to run the job
  • 可选:重复作业的时间和频率Optional: When and how often to repeat the job
  • 可选:主操作失败时运行的错误操作Optional: An error action that runs if the primary action fails

作业还包括系统提供的数据,例如,作业的下一次计划运行时间。The job also includes system-provided data such as the job's next scheduled run time. 作业的代码定义是一个 JavaScript 对象表示法 (JSON) 格式的对象,包括以下元素:The job's code definition is an object in JavaScript Object Notation (JSON) format, which has these elements:

元素Element 必须Required 说明Description
startTimestartTime No 作业的开始时间,时区偏移量为 ISO 8601 格式The start time for the job with a time zone offset in ISO 8601 format
actionaction Yes 主操作的详细信息,可以包含 errorAction 对象The details for the primary action, which can include an errorAction object
errorActionerrorAction No 主操作失败时运行的辅助操作的详细信息The details for the secondary action that runs if the primary action fails
recurrencerecurrence No 定期作业的频率和间隔等详细信息The details such as frequency and interval for a recurring job
retryPolicyretryPolicy No 有关重试操作的频率的详细信息The details for how often to retry an action
statestate Yes 作业当前状态的详细信息The details for the job's current state
status status Yes 作业当前状态的详细信息,由服务控制The details for the job's current status, which is controlled by the service

下面的示例显示了 HTTP 操作的综合作业定义,后面的部分中描述了更全面的元素详细信息:Here's an example that shows a comprehensive job definition for an HTTP action with fuller element details described in later sections:

"properties": {
   "startTime": "2012-08-04T00:00Z",
   "action": {
      "type": "Http",
      "request": {
         "uri": "http://contoso.com/some-method", 
         "method": "PUT",          
         "body": "Posting from a timer",
         "headers": {
            "Content-Type": "application/json"
         },
         "retryPolicy": { 
             "retryType": "None" 
         },
      },
      "errorAction": {
         "type": "Http",
         "request": {
            "uri": "http://contoso.com/notifyError",
            "method": "POST"
         }
      }
   },
   "recurrence": {
      "frequency": "Week",
      "interval": 1,
      "schedule": {
         "weekDays": ["Monday", "Wednesday", "Friday"],
         "hours": [10, 22]
      },
      "count": 10,
      "endTime": "2012-11-04"
   },
   "state": "Disabled",
   "status": {
      "lastExecutionTime": "2007-03-01T13:00:00Z",
      "nextExecutionTime": "2007-03-01T14:00:00Z ",
      "executionCount": 3,
      "failureCount": 0,
      "faultedCount": 0
   }
}

startTimestartTime

在 startTime 对象中,可以指定 ISO 8601 格式的开始时间和时区偏移量。In the startTime object, you can specify the start time and a time zone offset in ISO 8601 format.

actionaction

计划程序作业基于指定的计划运行主操作 。Your Scheduler job runs a primary action based on the specified schedule. 计划程序支持 HTTP、存储队列、服务总线队列和服务总线主题操作。Scheduler supports HTTP, Storage queue, Service Bus queue, and Service Bus topic actions. 如果主操作 失败,计划程序可以运行辅助 errorAction 处理该错误。If the primary action fails, Scheduler can run a secondary errorAction that handles the error. 操作对象描述了以下元素:The action object describes these elements:

  • 操作的服务类型The action's service type
  • 操作的详细信息The action's details
  • 替代的 errorAction An alternative errorAction

上一个示例介绍了 HTTP 操作。The previous example describes an HTTP action. 下面是存储队列操作的示例:Here's an example for a Storage queue action:

"action": {
   "type": "storageQueue",
   "queueMessage": {
      "storageAccount": "myStorageAccount",  
      "queueName": "myqueue",                
      "sasToken": "TOKEN",                   
      "message": "My message body"
    }
}

下面是服务总线队列操作的示例:Here's an example for a Service Bus queue action:

"action": {
   "type": "serviceBusQueue",
   "serviceBusQueueMessage": {
      "queueName": "q1",  
      "namespace": "mySBNamespace",
      "transportType": "netMessaging", // Either netMessaging or AMQP
      "authentication": {  
         "sasKeyName": "QPolicy",
         "type": "sharedAccessKey"
      },
      "message": "Some message",  
      "brokeredMessageProperties": {},
      "customMessageProperties": {
         "appname": "FromScheduler"
      }
   }
},

下面是服务总线主题操作的示例:Here's an example for a Service Bus topic action:

"action": {
   "type": "serviceBusTopic",
   "serviceBusTopicMessage": {
      "topicPath": "t1",  
      "namespace": "mySBNamespace",
      "transportType": "netMessaging", // Either netMessaging or AMQP
      "authentication": {
         "sasKeyName": "QPolicy",
         "type": "sharedAccessKey"
      },
      "message": "Some message",
      "brokeredMessageProperties": {},
      "customMessageProperties": {
         "appname": "FromScheduler"
      }
   }
},

有关共享访问签名 (SAS) 令牌的详细信息,请参阅使用共享访问签名授权For more information about Shared Access Signature (SAS) tokens, see Authorize with Shared Access Signatures.

errorActionerrorAction

如果作业的主操作 失败,计划程序可以运行 errorAction 处理该错误。If your job's primary action fails, Scheduler can run an errorAction that handles the error. 在主操作 中,可以指定 errorAction 对象,使计划程序可以调用错误处理的终结点或发送用户通知。In the primary action, you can specify an errorAction object so Scheduler can call an error-handling endpoint or send a user notification.

例如,如果主终结点发生灾难,可以使用 errorAction 调用辅助终结点,或者通知错误处理终结点。For example, if a disaster happens at the primary endpoint, you can use errorAction for calling a secondary endpoint, or for notifying an error handling endpoint.

与主操作 类似,可以使用基于其他操作的简单或复合逻辑来执行错误操作。Just like the primary action, you can have the error action use simple or composite logic based on other actions.

recurrencerecurrence

如果作业的 JSON 定义包含 recurrence 对象,则作业定期发生,例如:A job recurs if the job's JSON definition includes the recurrence object, for example:

"recurrence": {
   "frequency": "Week",
   "interval": 1,
   "schedule": {
      "hours": [10, 22],
      "minutes": [0, 30],
      "weekDays": ["Monday", "Wednesday", "Friday"]
   },
   "count": 10,
   "endTime": "2012-11-04"
},
属性Property 必须Required ValueValue 说明Description
frequencyfrequency 是,使用 recurrence 时Yes, when recurrence is used Minute、Hour、Day、Week、Month、Year"Minute", "Hour", "Day", "Week", "Month", "Year" 两次作业之间的时间单位The time unit between occurrences
intervalinterval No 1 - 1000(包含)1 to 1000 inclusively 一个正整数,根据频率 确定两次作业之间的时间单位数A positive integer that determines the number of time units between each occurrence based on frequency
scheduleschedule No 多种多样Varies 更复杂和更高级计划的详细信息。The details for more complex and advanced schedules. 请参阅 hours 、minutes 、weekDays 、months 和 monthDays See hours, minutes, weekDays, months, and monthDays
小时数hours No 1 - 241 to 24 一个带有小时标记的数组,用于指示何时运行作业An array with the hour marks for when to run the job
minutesminutes No 0 到 590 to 59 一个带有分钟标记的数组,用于指示何时运行作业An array with the minute marks for when to run the job
monthsmonths No 1 - 121 to 12 一个带有月份标记的数组,用于指示何时运行作业An array with the months for when to run the job
monthDaysmonthDays No 多种多样Varies 一个带有月份天数标记的数组,用于指示何时运行作业An array with the days of the month for when to run the job
工作日weekDays No Monday、Tuesday、Wednesday、Thursday、Friday、Saturday、Sunday"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" 一个带有星期的天数标记的数组,用于指示何时运行作业An array with days of the week for when to run the job
countcount No <无 ><none> 重复周期的次数。The number of recurrences. 默认为无限重复。The default is to recur infinitely. 不能同时使用 count 和 endTime ,但首先完成的规则优先。You can't use both count and endTime, but the rule that finishes first is honored.
endTimeendTime No <无 ><none> 停止重复周期的日期和时间。The date and time for when to stop the recurrence. 默认为无限重复。The default is to recur infinitely. 不能同时使用 count 和 endTime ,但首先完成的规则优先。You can't use both count and endTime, but the rule that finishes first is honored.

有关这些元素的详细信息,请参阅生成复杂的计划和高级重复周期For more information about these elements, see Build complex schedules and advanced recurrences.

retryPolicyretryPolicy

对于计划程序作业可能失败的情况,可以设置重试策略,确定计划程序是否重试操作以及如何重试。For the case when a Scheduler job might fail, you can set up a retry policy, which determines whether and how Scheduler retries the action. 默认情况下,计划程序以 30 秒的间隔继续重试作业四次。By default, Scheduler retries the job four more times at 30-second intervals. 可以使此策略或多或少具有攻击性,例如,此策略每天重试一个操作达两次:You can make this policy more or less aggressive, for example, this policy retries an action two times per day:

"retryPolicy": { 
   "retryType": "Fixed",
   "retryInterval": "PT1D",
   "retryCount": 2
},
属性Property 必须Required ValueValue 说明Description
retryTyperetryType Yes Fixed NoneFixed, None 确定是否指定重试策略(固定 )或(无 )。Determines whether you specify a retry policy (fixed) or not (none).
retryIntervalretryInterval No PT30SPT30S 指定每次重试尝试之间的间隔和频率(ISO 8601 格式)。Specifies the interval and frequency between retry attempts in ISO 8601 format. 最小值为 15 秒,最大值为 18 个月。The minimum value is 15 seconds, while the maximum value is 18 months.
retryCountretryCount No 44 指定重试尝试的次数。Specifies the number of retry attempts. 最大值为 20。The maximum value is 20.

有关详细信息,请参阅高可用性和可靠性For more information, see High availability and reliability.

statestate

作业的状态为“已启用” 、“已禁用” 、“已完成” 或“已出错” ,例如:A job's state is either Enabled, Disabled, Completed, or Faulted, for example:

"state": "Disabled"

若要将作业更改为“已启用” 或“已禁用” 状态,可以使用这些作业上的 PUT 或 PATCH 操作。To change jobs to Enabled or Disabled state, you can use the PUT or PATCH operation on those jobs. 尽管可以对作业执行 DELETE 操作,但是,如果作业为“已完成” 或“已出错” 状态,则无法更新状态。However, if a job has Completed or Faulted state, you can't update the state, although you can perform the DELETE operation on the job. 计划程序在 60 天后删除已完成的作业和已出错的作业。Scheduler deletes completed and faulted jobs after 60 days.

状态status

作业启动后,计划程序通过 status 对象返回作业状态的相关信息,它仅由计划程序控制。After a job starts, Scheduler returns information about the job's status through the status object, which only Scheduler controls. 不过,可以在 job 对象内找到 status 对象。However, you can find the status object inside the job object. 下面是作业的状态包含的信息:Here's the information that a job's status includes:

  • 上一次执行的时间(如果有)Time for the previous execution, if any
  • 正在进行的作业的下一次计划执行时间Time for the next scheduled execution for jobs in progress
  • 作业执行次数The number of job executions
  • 失败次数(如果有)The number of failures, if any
  • 出错次数(如果有)The number of faults, if any

例如:For example:

"status": {
   "lastExecutionTime": "2007-03-01T13:00:00Z",
   "nextExecutionTime": "2007-03-01T14:00:00Z ",
   "executionCount": 3,
   "failureCount": 0,
   "faultedCount": 0
}

另请参阅See also