将 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 continue working with the jobs that you set up in Scheduler, please move to Azure Logic Apps as soon as possible by following this article.

本文介绍如何通过使用 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 Blob 存储、Azure 服务总线、Office 365 Outlook 和 SAP)提供的随时可用的连接器生成作业。Build your job by using a visual designer and ready-to-use connectors from hundreds of services, such as Azure Blob Storage, Azure Service Bus, Office 365 Outlook, and SAP.

  • 将每个计划的工作流作为一级 Azure 资源进行管理。Manage each scheduled workflow as a first-class Azure resource. 不必担心作业集合的概念,因为每个逻辑应用都是单独的 Azure 资源。You don't have to worry about the concept of a job collection because each logic app is an individual Azure resource.

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

  • 设置支持时区并可自动调整为夏令时 (DST) 的计划。Set schedules that support time zones and automatically adjust to 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

使用脚本进行迁移Migrate by using a script

每个计划程序作业都是唯一的,因此不存在一个可以将计划程序作业迁移到 Azure 逻辑应用的通用工具。Each Scheduler job is unique, so no one-size-fits-all tool exists for migrating Scheduler jobs to Azure Logic Apps. 但是,可以根据需要编辑此脚本However, you can edit this script to meet your needs.

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

只需创建一个逻辑应用即可运行多个一次性作业。You can run multiple one-time jobs by creating just a single 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, select Use sample payload to generate schema.

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

      示例有效负载

  4. 在触发器下,选择“下一步”。 Under the trigger, select 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. 通过从数百个现成的连接器中进行选择,来添加要运行的任何其他操作。Add any other actions you want to run by selecting from hundreds of ready-to-use 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 select 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 that 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, select 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

  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. 通过从数百个现成的连接器中进行选择,来添加其他操作。Add other actions you want by selecting from hundreds of ready-to-use. 在触发器下,选择“下一步”。 Under the trigger, select 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 ellipses (...) menu, and select Settings.

    打开操作设置

  2. 选择所需的重试策略。Select the retry policy that 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 that you want to handle, move your pointer over the arrow between steps, and select 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 ellipses (...) 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, select 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 年 12 月 31 日完全停用。A: Azure Scheduler is scheduled to fully retire on December 31, 2019.

:该服务停用后,会对我的作业集合和作业有何影响?Q: What happens to my job collections and jobs after the service retires?
:所有计划程序作业集合和作业都会停止运行,然后会从系统中删除。A: All Scheduler job collections and jobs stop running and are 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. 但是,可以根据需求编辑此脚本,以便将 Azure 计划程序作业迁移到 Azure 逻辑应用However, based on your needs, you can edit this script to migrate Azure Scheduler jobs to Azure Logic Apps.

:迁移计划程序作业时,可从何处获得支持?Q: Where can I get support for migrating my Scheduler jobs?
:以下是获得支持的一些方法:A: Here are some ways to get support:

Azure 门户Azure portal

如果 Azure 订阅具有付费支持计划,则可以在 Azure 门户中创建技术支持请求。If your Azure subscription has a paid support plan, you can create a technical support request in the Azure portal. 如果没有,则可以选择其他支持选项。Otherwise, you can select a different support option.

  1. Azure 门户主菜单中,选择“帮助和支持” 。On the Azure portal main menu, select Help + support.

  2. 在“支持”菜单中选择“新建支持请求”。 From the Support menu, select New support request. 提供请求的以下信息:Provide this information about for your request:

    属性Property ValueValue
    问题类型Issue type 技术Technical
    订阅Subscription <your-Azure-subscription><your-Azure-subscription>
    服务Service 选择“计划程序” 。Select Scheduler.
  3. 选择所需的支持选项。Select the support option you want. 如果有付费支持计划,请选择“下一步” 。If you have a paid support plan, select Next.

社区Community

后续步骤Next steps