Search code examples
azurewindows-servicesazure-webjobsazure-webjobssdkazure-webjobs-triggered

Use WebJobs and WebJobs extensions nuget in windows service and on cloud


We have an application that runs as a windows service we are migrating to Azure. The windows service runs continuously and uses Quartz scheduler library internally to trigger different jobs configured with cron expressions.

Webjobs look like a good fit to host this application in the cloud, but with webjobs already having the "TimerTrigger" mechanism, which also works with a slightly less rich but sufficient, compared to quartz, set of cron exrpession, we should ideally remove the quartz altogether from the system and just configure the same "jobs" to run off the triggers configured for the webjobs. The Microsoft.Azure.WebJobs and Microsoft.Azure.WebJobs.Extensions provide enough functionality to do this. So far so good.

Meanwhile, the migration is a while away, since there are 50 other applications and design changes that must be addressed. In the interim, the application will run on premise as a windows service, and during the transition, should be able to run both on prem and in Azure.

As I worked through using the webjobs library, I saw empirical evidence that the Quartz library can be removed altogether, all the "jobs" triggered only using "TimerTrigger" from the webjobs packages, configured using HostBuilder.ConfigureWebJobs as described for use in Microsoft.Azure.WebJobs 3.0.14, and this is a .net Framework 4.7.2 application meanwhile (which can consume the webjobs .net standard library). The observation was:

  1. It works within Azure webjobs as expected
  2. It works ok on prem too as a Windows service, it runs ok, with all triggers firing from the webjobs packages and executes the jobs just fine.

Webjobs documentation or that for the nuget packages does not discuss the use of the packages for on-prem windows services hosted timer triggered jobs, but it seems to work ok.

I came across a similar discussion: Ways to leverage single code base between Windows Service and Azure WebJob but the takeaway was to use two different trigger mechanism for on prem and Azure. My testing suggests, the webjobs library can be used for both. Any

Can anyone advise if using just webjobs packages to work both on prem and on Azure is a workable approach or are there pitfalls I just haven't encoutered yet running it on prem?


Solution

  • Here're something that it cannot take use when running locally:

    1.It cannot take use of the auto-scale feature from azure, if the work-load is high.

    2.You cannot view the job history.

    3.You need to manage the hardware resources by yourself.

    If these things are not important to you, you can keep using it locally.

    Hope it helps.