繁体   English   中英

azure定时器function如何设置多个时间表?

[英]How to set multiple schedule in azure timer function?

我有一个工作示例 azure 计时器 function,但是关于在多个时间表中设置它,我不确定是否正确设置,因为我无法立即测试它,因为它是预定的时间间隔。

我的目标是,每天早上 8:00 和晚上 8:00 显示context.log

注意:我下面的代码实际上不起作用,因为参数hour不接受数组(仅用于演示目的)


这是我的代码:

export const TimerTrigger1 = TypedAzFunc.createFunctionBuilder(__dirname)
  .with(
    TimerTriggerPlugin.init({
      schedule: {
        crontab: {
          second: 0,
          minute: { interval: 1 },
          hour: [{ interval: 8 }, { interval: 20 }],
          day: '*',
          month: '*',
          dayOfWeek: '*',
        },
      },
    })
  )
  .build(async (context, timer) => {
    var timeStamp = new Date().toISOString()

    if (timer.isPastDue) {
      context.log('timer has already triggered')
    }
    context.log('timer has triggered', timeStamp)
  })

export const run = TimerTrigger1.run

您可以通过在hour属性中传递一个数组来实现这一点。

TimerTriggerPlugin.init({
  schedule: {
    crontab: {
      second: 0,
      minute: 0,
      hour: [8, 20],
      day: '*',
      month: '*',
      dayOfWeek: '*',
    },
  },
})

这将产生一个时间表,例如:

如果今天是 2022 年 2 月 18 日早上 7:00

02/18/2022 08:00:00Z
02/18/2022 20:00:00Z
02/18/2022 08:00:00Z
02/18/2022 20:00:00Z
02/18/2022 08:00:00Z

您可以通过设置 2 个计时器来解决此问题,一个用于上午 8 点,一个用于晚上 8 点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM