将 Azure 计划程序作业迁移到 Azure 逻辑应用Migrate Azure Scheduler jobs to Azure Logic Apps

Important

Azure 逻辑应用将替换即将停用的 Azure 计划程序。Azure Logic Apps is replacing Azure Scheduler, which is being retired. 若要安排作业,请按照本文说明迁移到 Azure 逻辑应用。To schedule jobs, follow this article for moving to Azure Logic Apps instead.

本文介绍如何通过使用 Azure 逻辑应用而非 Azure 计划程序来创建自动化工作流,从而安排一次性作业和重复作业。This article shows how you can schedule one-time and recurring jobs by creating automated workflows with Azure Logic Apps, rather than with Azure Scheduler. 使用逻辑应用创建计划的作业时,将获得以下好处:When you create scheduled jobs with Logic Apps, you get these benefits:

  • 不必担心作业集合的概念,因为每个逻辑应用都是一个单独的 Azure 资源。You don't have to worry about the concept of a job collection because each logic app is a separate Azure resource.

  • 可以使用单个逻辑应用运行多个一次性作业。You can run multiple one-time jobs by using a single logic app.

  • Azure 逻辑应用服务支持时区和夏令时 (DST)。The Azure Logic Apps service supports time zone and daylight savings time (DST).

若要了解详细信息,请参阅什么是 Azure 逻辑应用?To learn more, see What is Azure Logic Apps? 或尝试在此快速入门中创建第一个逻辑应用:创建第一个逻辑应用or try creating your first logic app in this quickstart: Create your first logic app.

先决条件Prerequisites

安排一次性作业Schedule one-time jobs

只需创建一个逻辑应用即可运行多个一次性作业。You can run multiple one-time jobs by creating just a single logic app.

创建逻辑应用Create your logic app

  1. Azure 门户的逻辑应用设计器中创建一个空白的逻辑应用。In the Azure portal, create a blank logic app in Logic App Designer.

    有关基本步骤,请遵循快速入门:创建第一个逻辑应用For the basic steps, follow Quickstart: Create your first logic app.

  2. 在搜索框中,输入“收到 http 请求时”作为筛选器。In the search box, enter "when a http request" as your filter. 从触发器列表中选择此触发器:“当收到 HTTP 请求时”From the triggers list, select this trigger: When a HTTP request is received

    添加“请求”触发器

  3. 对于请求触发器,可以选择提供 JSON 架构,这有助于逻辑应用设计器了解传入请求的输入结构,使你稍后在工作流中更易选择输出。For the Request trigger, you can optionally provide a JSON schema, which helps the Logic App Designer understand the structure for the inputs from the incoming request and makes the outputs easier for you to select later in your workflow.

    若要指定架构,请在“请求正文 JSON 架构”框中输入架构,例如:To specify a schema, enter the schema in the Request Body JSON Schema box, for example:

    请求架构

    如果你没有架构,但有一个 JSON 格式的示例有效负载,则可以基于该有效负载生成一个架构。If you don't have a schema, but you have a sample payload in JSON format, you can generate a schema from that payload.

    1. 在请求触发器中,选择“使用示例有效负载生成架构”。In the Request trigger, choose Use sample payload to generate schema.

    2. 在“输入或粘贴示例 JSON 有效负载”下,提供示例有效负载并选择“完成”,例如:Under Enter or paste a sample JSON payload, provide your sample payload, and then choose Done, for example:

      示例有效负载

  4. 在触发器下,选择“下一步”。Under the trigger, choose Next step.

  5. 在搜索框中,输入“延迟截止时间”作为筛选器。In the search box, enter "delay until" as your filter. 在操作列表下选择此操作:“延迟截止时间”Under the actions list, select this action: Delay until

    此操作会暂停逻辑应用工作流,直到指定的日期和时间。This action pauses your logic app workflow until a specified date and time.

    添加“延迟截止时间”操作

  6. 输入要启动逻辑应用工作流的时间戳。Enter the timestamp for when you want to start the logic app's workflow.

    在“时间戳”框内单击时,会显示动态内容列表,以便根据需要选择触发器的输出。When you click inside the Timestamp box, the dynamic content list appears so you can optionally select an output from the trigger.

    提供“延迟截止时间”详细信息

  7. 通过从大约 200 多个连接器中进行选择,来添加要运行的任何其他操作。Add any other actions you want to run by selecting from ~200+ connectors.

    例如,可以包含向 URL 发送请求的 HTTP 操作,或包含处理存储队列、服务总线队列或服务总线主题的操作:For example, you can include an HTTP action that sends a request to a URL, or actions that work with Storage Queues, Service Bus queues, or Service Bus topics:

    HTTP 操作

  8. 完成后,保存逻辑应用。When you're done, save your logic app.

    保存逻辑应用

    第一次保存逻辑应用时,逻辑应用的请求触发器的终结点 URL 会显示在“HTTP POST URL”框中。When you save your logic app for the first time, the endpoint URL for your logic app's Request trigger appears in the HTTP POST URL box. 如果要调用逻辑应用并将输入发送到逻辑应用进行处理,请使用此 URL 作为调用目标。When you want to call your logic app and send inputs to your logic app for processing, use this URL as the call destination.

    保存请求触发器终结点 URL

  9. 复制并保存此终结点 URL,以便稍后发送触发逻辑应用的手动请求。Copy and save this endpoint URL so you can later send a manual request that triggers your logic app.

启动一次性作业Start a one-time job

若要手动运行或触发一次性作业,请发送对逻辑应用的请求触发器终结点 URL 的调用。To manually run or trigger a one-time job, send a call to the endpoint URL for your logic app's Request trigger. 在此调用中,请指定要发送的输入或有效负载,你之前可能已通过指定架构进行了描述。In this call, specify the input or payload to send, which you might have described earlier by specifying a schema.

例如,通过使用 Postman 应用,可以采用与此示例类似的设置创建 POST 请求,然后选择“发送”以发出请求。For example, using the Postman app, you can create a POST request with the settings similar to this sample, and then choose Send to make the request.

请求方法Request method URLURL 正文Body 标头Headers
POSTPOST <endpoint-URL> rawraw

JSON(application/json)JSON(application/json)

在“raw”框中,输入要在请求中发送的有效负载。In the raw box, enter the payload you want to send in the request.

注意:此设置会自动配置“标头”值。Note: This setting automatically configures the Headers values.

:Content-TypeKey: Content-Type
:application/jsonValue: application/json

发送请求以手动触发逻辑应用

发送调用后,逻辑应用的响应会显示在“正文”选项卡中的“raw”框下方。After you send the call, the response from your logic app appears under the raw box on the Body tab.

Important

如果稍后想取消作业,请选择“标头”选项卡。在响应中查找并复制 x-ms-workflow-run-id 标头值。If you want to cancel the job later, choose the Headers tab. Find and copy the x-ms-workflow-run-id header value in the response.

响应

取消一次性作业Cancel a one-time job

在逻辑应用中,每个一次性作业均作为单个逻辑应用运行实例执行。In Logic Apps, each one-time job executes as a single logic app run instance. 若要取消一次性作业,可以使用逻辑应用 REST API 中的工作流运行 - 取消To cancel a one-time job, you can use Workflow Runs - Cancel in the Logic Apps REST API. 发送对触发器的调用时,请提供工作流运行 IDWhen you send a call to the trigger, provide the workflow run ID.

安排重复作业Schedule recurring jobs

创建逻辑应用Create your logic app

  1. Azure 门户的逻辑应用设计器中创建一个空白的逻辑应用。In the Azure portal, create a blank logic app in Logic App Designer.

    有关基本步骤,请遵循快速入门:创建第一个逻辑应用For the basic steps, follow Quickstart: Create your first logic app.

  2. 在搜索框中,输入“定期”作为筛选器。In the search box, enter "recurrence" as your filter. 从触发器列表中选择此触发器:“重复”From the triggers list, select this trigger: Recurrence

    添加“重复”触发器

  3. 如果需要,可以设置更高级的计划。Set up a more advanced schedule, if you want.

    高级计划

    有关高级计划选项的详细信息,请参阅使用 Azure 逻辑应用创建和运行重复任务和工作流For more information about advanced scheduling options, see Create and run recurring tasks and workflows with Azure Logic Apps

  4. 通过从 200 多个连接器中进行选择,来添加所需的其他操作。Add other actions you want by selecting from 200+ connectors. 在触发器下,选择“下一步”。Under the trigger, choose Next step. 查找并选择所需的操作。Find and select the actions you want.

    例如,可以包含向 URL 发送请求的 HTTP 操作,或包含处理存储队列、服务总线队列或服务总线主题的操作:For example, you can include an HTTP action that sends a request to a URL, or actions that work with Storage Queues, Service Bus queues, or Service Bus topics:

    HTTP 操作

  5. 完成后,保存逻辑应用。When you're done, save your logic app.

    保存逻辑应用

高级设置Advanced setup

下面是可以自定义作业的其他方法。Here are other ways you can customize your jobs.

重试策略Retry policy

若要控制在出现间歇性失败时操作尝试在逻辑应用中重新运行的方式,可以在每个操作的设置中设置重试策略,例如:To control the way that an action tries to rerun in your logic app when intermittent failures happen, you can set the retry policy in each action's settings, for example:

  1. 打开该操作的 (...) 菜单,选择“设置”。Open the action's (...) menu, and select Settings.

    打开操作设置

  2. 选择所需的重试策略。Select the retry policy you want. 有关每个策略的详细信息,请参阅重试策略For more information about each policy, see Retry policies.

    选择重试策略

处理异常和错误Handle exceptions and errors

在 Azure 计划程序中,如果默认操作无法运行,则可以运行解决错误情况的替代操作。In Azure Scheduler, if the default action fails to run, you can run an alterative action that addresses the error condition. 在 Azure 逻辑应用中,也可以执行相同的任务。In Azure Logic Apps, you can also perform the same task.

  1. 在逻辑应用设计器中要处理的操作上方,将指针移到各步骤之间的箭头上,然后选择“添加并行分支”。In Logic App Designer, above the action you want to handle, move your pointer over the arrow between steps, and select and Add a parallel branch.

    添加并行分支

  2. 查找并选择要作为替代操作运行的操作。Find and select the action you want to run instead as the alternative action.

    添加并行操作

  3. 在替代操作上,打开 (...) 菜单,选择“配置随后运行”。On the alternative action, open the (...) menu, and select Configure run after.

    配置随后运行

  4. 清除“成功”属性的相应框。Clear the box for the is successful property. 选择以下属性:“失败”、“已跳过”和“已超时”Select these properties: has failed, is skipped, and has timed out

    设置“随后运行”属性

  5. 完成后,选择“完成”。When you're finished, choose Done.

若要详细了解异常处理,请参阅处理错误和异常 - RunAfter 属性To learn more about exception handling, see Handle errors and exceptions - RunAfter property.

常见问题FAQ

:Azure 计划程序何时停用?Q: When is Azure Scheduler retiring?
:Azure 计划程序计划于 2019 年 9 月 30 日停用。A: Azure Scheduler is scheduled to retire on September 30, 2019.

:该服务停用后,会对我的计划程序作业集合和作业有何影响?Q: What happens to my Scheduler job collections and jobs after the service retires?
:将从系统中删除所有计划程序作业集合和作业。A: All Scheduler job collections and jobs will be deleted from the system.

:在将我的计划程序作业迁移到逻辑应用之前,是否必须备份或执行任何其他任务?Q: Do I have to back up or perform any other tasks before migrating my Scheduler jobs to Logic Apps?
:作为最佳做法,请始终备份你的工作。A: As a best practice, always back up your work. 在删除或禁用计划程序作业之前,请检查你创建的逻辑应用是否按预期运行。Check that the logic apps you created are running as expected before deleting or disabling your Scheduler jobs.

:是否有可以帮助我将作业从计划程序迁移到逻辑应用的工具?Q: Is there a tool that can help me migrate my jobs from Scheduler to Logic Apps?
:每个计划程序作业都是唯一的,因此不存在一个通用的工具。A: Each Scheduler job is unique, so a one-size-fits-all tool doesn't exist. 但是,可以使用各种脚本来根据需要进行修改。However, various scripts will be available for you to modify for your needs. 对于脚本可用性,请以后再回来查看。For script availability, check back later.

后续步骤Next steps