Justinfailber
Justinfailber

Reputation: 38

Microsoft Azure run function after x minutes

I'm hosting a C# ASP.net website on azure currently, and I'm searching for a function that lets me execute code to change database entries after x minutes after the request.

So for example:

User visits my website http://www.test.com/
Users leave my site.
5 minutes later I changed a variable in my database.

I already found something called WebJobs, but it's not the perfect fit.

Upvotes: 2

Views: 518

Answers (1)

Bruce Chen
Bruce Chen

Reputation: 18465

Per my understanding, you could log the action into Azure Storage Queue and specify the interval of time from now during which the message will be invisible as follows:

queue.AddMessage(new CloudQueueMessage("hello world"), initialVisibilityDelay:TimeSpan.FromMinutes(5));

Then, you could work with WebJobs SDK to trigger your Azure queue storage. More details, you could refer to How to use Azure queue storage with the WebJobs SDK. Also, you could leverage Azure Functions Queue bindings to achieve the similar requirement, details you could follow here.

Moreover, you could also leverage the Scheduled messages from Azure Service Bus. Also, here is a similar issue, you could refer to the related code for sending a scheduled message. For processing the messages, you could refer to How to use Azure Service Bus with the WebJobs SDK or Azure Functions Service Bus bindings.

My website creates a temp e-mail account for the visitor. That email needs to be deleted after x minutes.

Per my understanding, when you creating the temp e-mail account, you could record the create time and the expire time, and valid the temp account is valid or not when accessing your website. Then you could create a Recurring job (e.g. azure webjobs (TimerTrigger), or Hangfire,etc) to retrieve the expired accounts and delete them.

Upvotes: 2

Related Questions