Azure WebJobs

What is an Azure WebJob?  With WebJobs, you can simply run a program or script just like a running a web app. Azure Functions is also a similar service. You can create a console app and run it continuously or triggered. Let’s try a simple one.

  • Create the console app: dotnet new console
  • Write your code. Console.WriteLine outputs to WebJobs logs page. So you can use that to log simply.
  • Publish the project: dotnet publish -c Release
  • Add a new file with extension .cms, such as Run.cmd in the publish folder – we do this because webjobs do not run dll files directly. It will run this script file.
  • Add the command to run your dll: dotnet YourProject.dll
  • Zip the publish file: YourPorject.zip
  • Follow these steps to upload it to Azure and run it: https://docs.microsoft.com/en-us/azure/app-service/web-sites-create-web-jobs
  • You can use CRON expression for triggered jobs:

Every 15 minutes: 0 */15 * * * *
Every hour (that is, whenever the count of minutes is 0): 0 0 * * * *
Every hour from 9 AM to 5 PM: 0 0 9-17 * * *
At 9:30 AM every day: 0 30 9 * * *
At 9:30 AM every weekday: 0 30 9 * * 1-5

For more advanced features, you can use WebJobs SDK:
https://github.com/Azure/azure-webjobs-sdk

Resources:

WebJobs:
https://docs.microsoft.com/en-us/azure/app-service/web-sites-create-web-jobs

WebJobs vs. Functions:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-compare-logic-apps-ms-flow-webjobs

http://www.hanselman.com/blog/IntroducingWindowsAzureWebJobs.aspx

CRON Expressions Cheat Sheet:
https://codehollow.com/2017/02/azure-functions-time-trigger-cron-cheat-sheet/

Advertisements

#azure, #azure-functions, #azure-webjobs, #webjobs