在 Azure 逻辑应用中使用“滑动窗口”触发器来计划和运行处理连续数据的任务Schedule and run tasks for contiguous data by using the Sliding Window trigger in Azure Logic Apps

若要定期运行那些必须以连续区块的形式处理数据的任务、进程或作业,可以使用滑动窗口触发器来启动逻辑应用工作流。To regularly run tasks, processes, or jobs that must handle data in contiguous chunks, you can start your logic app workflow with the Sliding Window 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 processes those missed recurrences. 例如,在数据库和备份存储之间同步数据时,请使用“滑动窗口”触发器,使数据在同步时没有产生间隔。For example, when synchronizing data between your database and backup storage, use the Sliding Window trigger so that the data gets synchronized without incurring gaps. 有关内置计划触发器和操作的详细信息,请参阅使用 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:

  • 立即运行,并每隔 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. 使用此触发器时,可以指定过去的一个开始时间,以便运行所有过去的定期触发。With this trigger, you can specify a start time in the past, which runs all past recurrences.

  • 将每个定期触发延迟特定的时间,然后再运行。Delay each recurrence for a specific duration before running.

有关此触发器与定期触发器之间的差异或有关计划重复执行工作流的详细信息,请参阅使用 Azure 逻辑应用计划和运行定期自动执行的任务、进程和工作流For differences between this trigger and the Recurrence 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 Sliding Window trigger

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

  2. 显示逻辑应用设计器后,在搜索框中输入 sliding window 作为筛选器。After the Logic App Designer appears, in the search box, enter sliding window as your filter. 从触发器列表中选择“滑动窗口”触发器,这是逻辑应用工作流的第一步。From the triggers list, select the Sliding Window trigger as the first step in your logic app workflow.

    选择“滑动窗口”触发器

  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

    高级定期选项

    如需更多定期选项,请打开“添加新参数”列表。For more recurrence options, open the Add new parameter list. 选择的任何选项会在选定后显示在触发器中。Any options that you select appear on the trigger after selection.

    属性Property 必须Required JSON 名称JSON name 类型Type 说明Description
    延迟Delay No delaydelay StringString 根据 ISO 8601 日期时间规范延迟每个定期的时间The duration to delay each recurrence using the ISO 8601 date time specification
    时区Time zone No timezonetimeZone 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 No startTimestartTime 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

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

    注意: 此开始时间必须遵循 ISO 8601 日期时间规范,采用 UTC 日期时间格式但没有 UTC 时差Note: This start time 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 advanced recurrences, the trigger doesn't fire any sooner than the start time. 可通过哪些方式使用开始日期和时间? What are the ways that I can use the start date and time?

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

工作流定义 - 滑动窗口Workflow definition - Sliding Window

在逻辑应用的基础工作流定义(使用 JSON)中,可以通过选定的选项查看“滑动窗口”触发器定义。In your logic app's underlying workflow definition, which uses JSON, you can view the Sliding Window 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.

本示例介绍了“滑动窗口”触发器定义在基础工作流定义中看起来是什么样的,具体说来,对于按小时进行的重复触发,每个重复触发的延迟是 5 秒:This example shows how a Sliding Window trigger definition might look in an underlying workflow definition where the delay for each recurrence is five seconds for an hourly recurrence:

"triggers": {
   "Recurrence": {
      "type": "SlidingWindow",
      "Sliding_Window": {
         "inputs": {
            "delay": "PT5S"
         },
         "recurrence": {
            "frequency": "Hour",
            "interval": 1,
            "startTime": "2019-05-13T14:00:00Z",
            "timeZone": "Pacific Standard Time"
         }
      }
   }
}

后续步骤Next steps