Reputation: 2166
I have a working sample azure timer function, but about setting it in multiple schedule, I'm not sure if doing it correctly, because I can't test it immediately because it is scheduled hours gap.
My goal is, to display context.log
every 8:00AM, and 8:00PM every day.
note: my code below actually don't work because parameter
hour
does not accept array (for demonstration purpose only)
Here is my code:
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
Upvotes: 0
Views: 552
Reputation: 2331
you can achieve this, by passing an array in the hour
property.
TimerTriggerPlugin.init({
schedule: {
crontab: {
second: 0,
minute: 0,
hour: [8, 20],
day: '*',
month: '*',
dayOfWeek: '*',
},
},
})
this will result a schedule for example:
if today is february 18, 2022 7:00am
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
Upvotes: 0
Reputation: 65461
You could solve this by having 2 timers, one for 8 am and one for 8 pm.
Upvotes: 0