Reputation: 421
Looking for some self triggering function which starts on a time given.
eg. A user has a conference to start at 25/04/2019 05:30 Here the user should get a notification at 25/04/2019 05:25 | 05:29 That the conference is about to start.
Have created a azure function (Time triggred) which triggers every minute and checks if current time is the Conference Time - 4 minutes, Then send a notification regarding conference to be started.
In future will have multiple users and so I do not want the function to run every minute, Is there a way in which at 05:25 or at the conference time the function will execute itself. So there can be 100 users and they will have different. Just looking for options about how to implement in a better way.
.net core site, hosted on azure, Have azure functions running every minute to check the remainder
Upvotes: 1
Views: 1272
Reputation: 13488
When user registered on conference you can queue message(with user details) to queue with visibility delay:
queue.AddMessage(message, initialVisibilityDelay: TimeSpanDelay);
For example, user registered at 6 PM, and conference will be next day at 8 PM, so delay time will be 25 hours and and 55 minutes(supposed, that user want to be notified 5 minutes before conference). Then instead of time triggered function you will use queue triggered function, which will send notifications, when messages from queue become visible:
public static void Run([QueueTrigger("notifications")]QueueTrigger message, TraceWriter log)
{
Notifier.Send(message.UserName, message.UserPhoneNumber, message.Email);
}
Moreover, if by some reason your notification handler will be failed, queue messages will not be lost, so you can retry to process them several times.
Upvotes: 4
Reputation: 14324
From your description, you already have a TimerTrigger Function however your Timer set the function running every minutes. Actually you could set more precise Timer trigger with CRON expressions.
This is CRON expressions in Azure Function, it includes six fields:{second} {minute} {hour} {day} {month} {day-of-week}
. So you could set your Function 0 25,29 5 22 March *
.
And after you deploy the function to Azure, it will keep running however it won't execute the Run method until it triggers the Timer.
public static void Run(TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
Upvotes: -1
Reputation: 1203
I recommend you to write a windows service using quartz library to schedule a job. You can pickup the job schedule time from db or somewhere.
Refer: https://www.quartz-scheduler.net
Upvotes: 0