Azure Webjobs - Deploy and manage them from your Node App

Have you ever wanted to manage your Webjobs directly from your Node app without having to browse the Azure portal?
You can also define if they would be triggered or continuous and also set the CRON expression for the triggered one.

Folder structure for your webjobs

There is a specific folder structure you should follow so that Azure can pick up your Javascript files and show them in the Webjobs settings.

App_Data 
│
└──jobs
   │
   └───triggered
       │   
       └───demo-webjob
            │
            └─run.js

Create your run.js file in the above structure and push your changes. Refresh your Webjobs in Azure portal and you should be able to see it. If not, refresh again. :grimacing:

Webjob

Add the CRON expression

Sweet. We now have a triggered webjob but we haven’t scheduled any CRON expression for it yet. We just need to add a settings.job file in our webjob folder.

//settings.job
{
  "schedule": "0 */15 * * * *"
}

The six fields of a CRON expression are:

{second} {minute} {hour} {day} {month} {day-of-week}

The above CRON expression will run the webjob every 15 minutes. Check this link for some CRON examples.

After adding the settings.job you should be able to see your CRON expression appear under the SCHEDULE column.

Webjob-CRON

Continuous Webjob

Great, we have added a triggered webjob and set up how often it will run. You can follow the same process to add a continuous webjob. The difference between the two is that the continuous one will run only once its created. If you want it to run endlessly you have to handle that inside your code.

So the full folder structure for our two webjobs would be:

App_Data 
│
└──jobs
   │
   |───triggered
   |    │   
   |    └───demo-webjob
   |         │
   |         └─run.js
   └───continuous
        |
        └───continuous-webjob
            |
            └─anotherWebjob.js

And the final result in Azure portal would be:

Webjob-2

Folder structure on GitHub: https://github.com/vaskort/vaskort.github.io/tree/second-post/App_Data

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

Cron examples: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer#cron-examples

Written on March 24, 2018

Subscribe to the Newsletter

I occasionaly publish a blog post, subscribe if you want to get notified when I publish one :)

    I respect your privacy and there will be no spam. Unsubscribe at any time.

    Powered By ConvertKit