0

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.

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?

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • 2
    Check out [Hangfire](http://hangfire.io/) for automated jobs, much easier to do. Or as you are in Azure, I think [WebJobs](https://azure.microsoft.com/en-gb/documentation/articles/web-sites-create-web-jobs/) might do it. – DavidG Aug 15 '16 at 15:44
  • Thanks. But I was hoping for some point in the application where I could call a function. If possible would like to not add in other apps to do the job :-( – Alan2 Aug 15 '16 at 16:48
  • 1
    Hangfire is not another application, it's just added as a Nuget package and WebJobs are part of Azure. There is no other way to get a regular task running in a web project. – DavidG Aug 15 '16 at 16:49
  • @DavidG he could use a Timer. But I get the feeling this is an [x/y problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) anyhow. –  Aug 15 '16 at 16:50
  • 1
    @Will Well a timer would be vulnerable to app recycling etc. That's why there are tools like Hangfire to take this pain away. But I do agree it's likely x/y. – DavidG Aug 15 '16 at 16:52

3 Answers3

1

This sounds like a job for an Azure Worker Role or an Azure WebJob. Depending on the scope of what you want to do. Azure Web Role for something a little more complicated.

1

I'm using Azure Function for a similar job - updating a DB every few minutes (in my case DocumentDB). It has a timer trigger where you can provide your Cron expression for timer based operations. https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-timer/

The only problem I have is version control on the code that is deployed to the Azure Function.

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

Community
  • 1
  • 1
shachar
  • 589
  • 3
  • 12
1

Maybe you can try Azure Scheduler which you can simply configure to call your Web API every minute.

Abhay Saraf
  • 1,202
  • 9
  • 19