Microsoft Azure在x分钟后运行功能

时间:2017-11-12 21:51:55

标签: c# asp.net azure

我目前在azure上托管我的C#ASP.net网站,我正在寻找一个功能,让我在执行代码后在x分钟后更改数据库条目请求。

所以我的例子:

用户访问我的网站http://www.test.com/
用户离开我的网站 5分钟后,我更改了数据库中的变量。

我已经找到了一种名为WebJobs的东西,但它并不完美。

1 个答案:

答案 0 :(得分:1)

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.