简体   繁体   English

如何使运行在Azure实例中的ASP.NET WebAPI程序每分钟更新一次数据库?

[英]How can I make an ASP.NET WebAPI program running in an Azure instance update a database every minute?

I'm very familiar with using WebAPI to respond to incoming HTTP requests but now I have a new requirement and I'm not really sure where to start. 我对使用WebAPI响应传入的HTTP请求非常熟悉,但是现在我有了新的要求,我不确定从哪里开始。

What I would like to do is to have my application once deployed to the cloud, establish a connection to a database and update a column every minute. 我想做的就是将我的应用程序部署到云中之后,建立与数据库的连接并每分钟更新一列。 The code needed to establish the connection and update the column is easy but my question is, where could I put this code? 建立连接和更新列所需的代码很简单,但我的问题是,该代码可以放在哪里? Is there some part of a normal ASP.NET WebAPI such as one of the start files where I could code this and how/where could I put a function call? 是否有普通ASP.NET WebAPI的某些部分,例如其中一个我可以对其进行编码的起始文件,以及如何/在何处进行函数调用?

This sounds like a job for an Azure Worker Role or an Azure WebJob . 这听起来像是Azure工作者角色Azure WebJob的工作 Depending on the scope of what you want to do. 根据您要做什么的范围。 Azure Web Role for something a little more complicated. Azure Web Role稍微复杂一点。

I'm using Azure Function for a similar job - updating a DB every few minutes (in my case DocumentDB). 我正在使用Azure Function进行类似的工作-每隔几分钟更新一次数据库(在我的情况下为DocumentDB)。 It has a timer trigger where you can provide your Cron expression for timer based operations. 它具有计时器触发器,您可以在其中为基于计时器的操作提供Cron表达式。 https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-timer/ https://azure.microsoft.com/zh-CN/documentation/articles/functions-bindings-timer/

The only problem I have is version control on the code that is deployed to the Azure Function. 我唯一的问题是对部署到Azure函数的代码的版本控制。

It's actually built on top of the Azure Webjobs SDK , you can read about the differences here - Azure Webjobs vs Azure Functions : How to choose 它实际上是建立在Azure Webjobs SDK之上的,您可以在此处了解差异-Azure Webjobs与Azure Functions:如何选择

也许您可以尝试Azure计划程序 ,您可以将其配置为每分钟调用Web API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM