使用 Azure 逻辑应用中的定期触发器创建、计划和运行重复任务和工作流Create, schedule, and run recurring tasks and workflows with the Recurrence trigger in Azure Logic Apps

若要按特定的计划定期运行任务、进程或作业,可以使用内置的定期 - 计划触发器来启动逻辑应用工作流。To regularly run tasks, processes, or jobs on specific schedule, you can start your logic app workflow with the built-in Recurrence - Schedule trigger. 可以设置启动工作流的日期、时间和时区,以及设置设置重复该工作流的定期计划。You can set a date and time as well as a time zone for starting the workflow and a recurrence for repeating that workflow. 如果由于某种原因错过了重复周期(例如,由于中断或工作流禁用而错过),则此触发器不会处理错过的重复周期,但会按下一个计划的时间间隔重启重复周期。If recurrences are missed for any reason, for example, due to disruptions or disabled workflows, this trigger doesn't process the missed recurrences but restarts recurrences at the next scheduled interval. 有关内置计划触发器和操作的详细信息,请参阅使用 Azure 逻辑应用计划和运行定期自动执行的任务和工作流For more information about the built-in Schedule triggers and actions, see Schedule and run recurring automated, tasks, and workflows with Azure Logic Apps.

下面是此触发器支持的一些模式,以及更高级的定期计划和复杂计划:Here are some patterns that this trigger supports along with more advanced recurrences and complex schedules:

  • 立即运行,并每隔 n 秒、分钟、小时、天、周或月重复运行。Run immediately and repeat every n number of seconds, minutes, hours, days, weeks, or months.

  • 在特定的日期和时间启动,然后运行并每隔 n 秒、分钟、小时、天、周或月重复运行。Start at a specific date and time, then run and repeat every n number of seconds, minutes, hours, days, weeks, or months.

  • 运行并在每天的一个或多个不同时间(例如 8:00 AM 和 5:00 PM)重复。Run and repeat at one or more times each day, for example, at 8:00 AM and 5:00 PM.

  • 运行并在每周的特定星期日期(例如星期六和星期日)重复。Run and repeat each week, but only for specific days, such as Saturday and Sunday.

  • 运行并在每周的特定星期日期和时间(例如星期一到星期五的 8:00 AM 和 5:00 PM)重复。Run and repeat each week, but only for specific days and times, such as Monday through Friday at 8:00 AM and 5:00 PM.

有关此触发器与“滑动窗口”触发器之间的差异或有关计划重复执行工作流的详细信息,请参阅使用 Azure 逻辑应用计划和运行定期自动执行的任务、流程和工作流For differences between this trigger and the Sliding Window trigger or for more information about scheduling recurring workflows, see Schedule and run recurring automated tasks, processes, and workflows with Azure Logic Apps.

提示

若要触发逻辑应用并且在将来仅运行一次,请参阅仅运行一次作业If you want to trigger your logic app and run only one time in the future, see Run jobs one time only.

先决条件Prerequisites

添加“定期”触发器Add Recurrence trigger

  1. 登录到 Azure 门户Sign in to the Azure portal. 创建空白逻辑应用。Create a blank logic app.

  2. 显示逻辑应用设计器后,在搜索框中输入 recurrence 作为筛选器。After Logic App Designer appears, in the search box, enter recurrence as your filter. 逻辑应用工作流的第一步是从触发器列表中选择此触发器。定期From the triggers list, select this trigger as the first step in your logic app workflow: Recurrence

    选择“定期”触发器

  3. 设置定期计划的间隔和频率。Set the interval and frequency for the recurrence. 在此示例中,请将这些属性设置为每周运行工作流。In this example, set these properties to run your workflow every week.

    设置间隔和频率

    属性Property JSON 名称JSON name 必须Required 类型Type 说明Description
    时间间隔Interval interval Yes IntegerInteger 一个正整数,描述工作流基于频率运行的频繁度。A positive integer that describes how often the workflow runs based on the frequency. 下面是最小和最大间隔:Here are the minimum and maximum intervals:

    - 月:1-16 个月- Month: 1-16 months
    - 周:1-71 周- Week: 1-71 weeks
    - 天:1-500 天- Day: 1-500 days
    - 小时:1-12,000 小时- Hour: 1-12,000 hours
    - 分钟:1-72,000 分钟- Minute: 1-72,000 minutes
    - 秒:1-9,999,999 秒- Second: 1-9,999,999 seconds

    例如,如果间隔为 6,频率为“月”,则重复周期为每 6 个月。For example, if the interval is 6, and the frequency is "Month", then the recurrence is every 6 months.

    频率Frequency frequency Yes StringString 定期计划的时间单位:“秒”、“分钟”、“小时”、“天”、“周”或“月” The unit of time for the recurrence: Second, Minute, Hour, Day, Week, or Month

    重要

    如果重复周期未指定高级计划选项,则将来的重复周期将基于上次运行时间。When recurrences don't specify advanced scheduling options, future recurrences are based on the last run time. 这些重复周期的开始时间可能会因存储调用期间的延迟等因素而发生偏移。The start times for these recurrences might drift due to factors such as latency during storage calls. 为了确保逻辑应用不会错过重复周期,特别是当频率为几天或更长的时间时,请使用以下选项之一:To make sure that your logic app doesn't miss a recurrence, especially when the frequency is in days or longer, use one of these options:

    • 提供重复周期的开始时间。Provide a start time for the recurrence.

    • 使用“在这些小时”和“在这些分钟”属性指定何时运行重复周期的小时和分钟。Specify the hours and minutes for when to run the recurrence by using the At these hours and At these minutes properties.

    • 使用滑动窗口触发器,而不是使用重复触发器。Use the Sliding Window trigger, rather than the Recurrence trigger.

  4. 若要设置高级计划选项,请打开“添加新参数”列表。To set advanced scheduling options, open the Add new parameter list. 选择的任何选项会在选定后显示在触发器中。Any options that you select appear on the trigger after selection.

    高级计划选项

    属性Property JSON 名称JSON name 必须Required 类型Type 说明Description
    时区Time zone timeZone No StringString 仅当指定启动时间时才适用,因为此触发器不接受 UTC 时差Applies only when you specify a start time because this trigger doesn't accept UTC offset. 选择要应用的时区。Select the time zone that you want to apply.
    开始时间Start time startTime No StringString 采用以下格式提供启动日期和时间:Provide a start date and time in this format:

    如果选择了时区,则格式为 YYYY-MM-DDThh:mm:ssYYYY-MM-DDThh:mm:ss if you select a time zone

    -或--or-

    如果未选择时区,则格式为 YYYY-MM-DDThh:mm:ssZYYYY-MM-DDThh:mm:ssZ if you don't select a time zone

    例如,如果需要 2020 年 9 月 18 日下午 2 点,则指定“2020-09-18T14:00:00”并选择时区(如“太平洋标准时间”)。So for example, if you want September 18, 2020 at 2:00 PM, then specify "2020-09-18T14:00:00" and select a time zone such as Pacific Standard Time. 或者,指定“2020-09-18T14:00:00Z”且不选择时区。Or, specify "2020-09-18T14:00:00Z" without a time zone.

    注意: 此开始时间在未来最长为 49 年,并且必须遵循 UTC 日期时间格式ISO 8601 日期时间规范,但没有 UTC 时差Note: This start time has a maximum of 49 years in the future and must follow the ISO 8601 date time specification in UTC date time format, but without a UTC offset. 如果未选择时区,必须在末尾添加字母“Z”(无空格)。If you don't select a time zone, you must add the letter "Z" at the end without any spaces. 这个“Z”指等效的航海时间This "Z" refers to the equivalent nautical time.

    对于简单计划,开始时间指首次运行时间;对于复杂计划,触发器的激发时间不会早于开始时间。For simple schedules, the start time is the first occurrence, while for complex schedules, the trigger doesn't fire any sooner than the start time. 可通过哪些方式使用开始日期和时间? What are the ways that I can use the start date and time?

    在这些日期On these days weekDays No 字符串或字符串数组String or string array 如果选择“周”,则可以选择要运行工作流的一天或多天:“星期一”、“星期二”、“星期三”、“星期四”、“星期五”、“星期六”和“星期日” If you select "Week", you can select one or more days when you want to run the workflow: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday
    在这些小时At these hours hours No 整数或整数数组Integer or integer array 如果选择了“天”或“周”,则可以从 0 到 23 的范围内选择一个或多个整数,作为当天要运行工作流的小时时间。If you select "Day" or "Week", you can select one or more integers from 0 to 23 as the hours of the day for when you want to run the workflow.

    例如,如果指定“10”、“12”和“14”,则会将上午 10 点、中午 12 点和下午 2 点作为当天的小时,但当天的分钟则根据定期启动的时间计算。For example, if you specify "10", "12" and "14", you get 10 AM, 12 PM, and 2 PM for the hours of the day, but the minutes of the day are calculated based on when the recurrence starts. 若要设置一天中的特定分钟,例如上午 10 点、中午 12 点和下午 2 点,请使用“在这些分钟”属性指定这些值。To set specific minutes of the day, for example, 10:00 AM, 12:00 PM, and 2:00 PM, specify those values by using the At these minutes property.

    在这些分钟At these minutes minutes No 整数或整数数组Integer or integer array 如果选择了“天”或“周”,则可以从 0 到 59 的范围内选择一个或多个整数,作为要运行工作流的小时时间的分钟时间。If you select "Day" or "Week", you can select one or more integers from 0 to 59 as the minutes of the hour when you want to run the workflow.

    例如,可以指定“30”作为分钟标记并使用前面示例中的当天小时时间,这样,便可以指定10:30 AM、12:30 PM 和 2:30 PM 作为开始时间。For example, you can specify "30" as the minute mark and using the previous example for hours of the day, you get 10:30 AM, 12:30 PM, and 2:30 PM.

    例如,假设当天是 2020 年 9 月 4 日星期五。For example, suppose that today is Friday, September 4, 2020. 以下“定期”触发器不会在开始日期和时间 2020 年 9 月 18 日星期五上午 8 点(太平洋标准时间)之前激发。The following Recurrence trigger doesn't fire any sooner than the start date and time, which is Friday, September 18, 2020 at 8:00 AM PST. 但是,该定期计划设置为仅在每个星期一的 10:30 AM、12:30 PM 和 2:30 PM 运行。However, the recurrence schedule is set for 10:30 AM, 12:30 PM, and 2:30 PM on Mondays only. 因此,首次激发触发器并创建逻辑应用工作流实例的时间为星期一上午 10 点 30 分。So the first time that the trigger fires and creates a logic app workflow instance is on Monday at 10:30 AM. 若要详细了解开始时间的工作方式,请参阅这些开始时间示例To learn more about how start times work, see these start time examples.

    将来的运行发生在同一天的 12:30 PM 和 2:30 PM。Future runs happen at 12:30 PM and 2:30 PM on the same day. 每个定期计划会创建其自身的工作流实例。Each recurrence creates their own workflow instance. 之后,在下一个星期一,整个计划会再次从头开始重复。After that, the entire schedule repeats all over again next Monday. 还有哪些计划示例? What are some other example occurrences?

    高级计划示例

    备注

    仅当选择“天”或“周”作为频率时,触发器才显示指定的定期计划的预览。The trigger shows a preview for your specified recurrence only when you select "Day" or "Week" as the frequency.

  5. 现在,请使用其他操作生成剩余的工作流。Now build your remaining workflow with other actions. 有关可添加的其他操作,请参阅 Azure 逻辑应用的连接器For more actions that you can add, see Connectors for Azure Logic Apps.

工作流定义 - 定期Workflow definition - Recurrence

在逻辑应用的基础工作流定义(使用 JSON)中,可以通过选定的选项查看“定期”触发器定义In your logic app's underlying workflow definition, which uses JSON, you can view the Recurrence trigger definition with the options that you chose. 若要查看此定义,请在设计器工具栏上选择“代码视图”。To view this definition, on the designer toolbar, choose Code view. 若要返回到设计器,请选择设计器工具栏上的“设计器”。To return to the designer, choose on the designer toolbar, Designer.

本示例介绍了“定期”触发器定义在基础工作流定义中看起来是什么样的:This example shows how a Recurrence trigger definition might look in an underlying workflow definition:

"triggers": {
   "Recurrence": {
      "type": "Recurrence",
      "recurrence": {
         "frequency": "Week",
         "interval": 1,
         "schedule": {
            "hours": [
               10,
               12,
               14
            ],
            "minutes": [
               30
            ],
            "weekDays": [
               "Monday"
            ]
         },
         "startTime": "2020-09-07T14:00:00Z",
         "timeZone": "Pacific Standard Time"
      }
   }
}

后续步骤Next steps