我目前在 azure 上托管我的 C# ASP.net 网站,我正在寻找一个函数,让我在请求后 x 分钟后执行代码以更改数据库条目。
所以我的例子:
用户访问我的网站http://www.test.com/
用户离开我的网站。
5 分钟后,我更改了数据库中的变量。
我已经找到了一个名为 WebJobs 的东西,但这并不是完美的选择。
最佳答案
根据我的理解,您可以将操作记录到 Azure Storage Queue并指定从现在开始消息不可见的时间间隔,如下所示:
queue.AddMessage(new CloudQueueMessage("hello world"), initialVisibilityDelay:TimeSpan.FromMinutes(5));
然后,您可以使用 WebJobs SDK 来触发 Azure 队列存储。更多详情,您可以引用How to use Azure queue storage with the WebJobs SDK 。此外,您可以利用 Azure Functions 队列绑定(bind)来实现类似的要求,详细信息您可以关注 here .
此外,您还可以利用 Scheduled messages来自 Azure 服务总线。另外,这里有一个类似的 issue ,您可以引用发送定时消息的相关代码。消息处理可以引用 How to use Azure Service Bus with the WebJobs SDK或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.
据我了解,当您创建临时电子邮件帐户时,您可以记录创建时间和过期时间,并在访问您的网站时验证临时帐户是否有效。然后,您可以创建一个定期作业(例如 azure webjobs ( TimerTrigger ) 或 Hangfire 等)来检索过期帐户并将其删除。
关于c# - x 分钟后 Microsoft Azure 运行功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47254411/