Search code examples
asp.netazurehangfire

How to get Hangfire started ("always on") in Azure shared hosting?


I want to deploy a simple shared-host ASP.NET MVC site to Azure (using the free site option) which uses Hangfire to run scheduled tasks.

Problem is the site only starts on the first request, and so Hangfire doesn't start scheduling tasks until then. With IIS or a dedicated VM, you can set the "always on" option to prewarm the site. But this is not possible in shared hosting.

What can I do about this? I thought of paying for the smallest VM, called "A0", and putting a ping script on there to ensure my site is always up. That would work, but seems like overkill.

Are there any other good options?


Solution

  • If you still would like to use azure website you have to switch from SHARED to BASIC (that's the first one with ALWAYS ON option), but it's more than 3 times more expensive than the cheapest VM.

    If I were you I would go for cheapest Cloud Service - Web Role. It cost a bit more than the cheapest VM but it's already configured for web sites and you don't have to set up everything on your own + you can use Visual Studio to deploy it, you can RDP to the box and many many more.

    See http://azure.microsoft.com/en-us/pricing/details/cloud-services/ for pricing details.

    But as suggested in comments Azure Schedule is something worth looking at.

    UPDATE: (WARNING - interesting but completely not serious solution)

    Use Azure Scheduler to ping you web page to keep it alive ;-) You can create up to 5 jobs with maximum execution every hour with FREE tier. Which means that you can create 5 jobs which will ping you website every 12 minutes.