簡體   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