Dynamics CRM, Web Job and Azure scheduler

Let us built upon our previous example where we created a Hello World console application, hosted it as web job in Azure App Service and then scheduled it using Azure Scheduler.

Scheduling a Web Job (console application) using Azure Scheduler

Here we will basically update the code in Console Application to use CRM’s assemblies.

Just for simplicity we’d create a lead record in our app and then schedule it to run every 2 minute for total of 5 occurrences.

In real world, obviously, we’d have different scenarios like checking for the status of records and send mail every 24 hour or so, or delete records periodically etc.

We have added the required CRM assemblies

The code to create lead record.

Publishing the updated code.

Running it.

Checking the logs.

Inside CRM it creates the lead record

Now let us re visit our Azure Job Scheduler, update the schedule to run 5 times with interval of 2 minutes.

Click on Run now to run the Job.

We can check the history of the Scheduler Job once it completes –

Logs of the Web Job –

5 Records created in CRM with interval of 2 minutes.

Hope it helps..

Scheduling a Web Job (console application) using Azure Scheduler

Let us a create a simple console application that writes Hello World to the console which we would be scheduling using Azure Scheduler.

Have kept the example simple so that we can understand the configuration part.

Right click on the project and Publish it as Azure WebJob

We will set the mode as “Run On Demand”

For the pubish target we have selected Microsoft Azure App Service web app under which this Web Job will run.

Select the App Service or configure a new one, we have selected the existing App Service below

Click on Validate to check the connection, if everything is fine Click Next and Publish the web role.

Our TriggeredWebJob inside CRMAzureWebJob App Service

We can run it on Demand by clicking on Run.

Clicking on Logs

Will provide the details of the Web Jobs

Now to schedule the Web Job we need to create a Scheduler Job, for this go to Scheduler Job Collections and click on Add

Create a new Job inside Job Collection and provide the required details like Name, Pricing Tier, Resource Group etc.

Next step is to configure the Action settings, wherein we will trigger our Web Job.

For this we need to define Action as Https, Method as Post and the URL

Format of the URL should be like –

https://{userName}:{password}@{WebAppName}.scm.azurewebsites.net/api/triggeredwebjobs/{WebJobName}/run

To get the above details open the Web Job properties


Replace the appropriate values

https://$CRMAzureWebJob:hyNboz8Skys3yrQ2MkpYnseXr7Kborq82JhEX09B32ExtjiYkxxgwejqsH@crmazurewebjob.scm.azurewebsites.net/api/triggeredwebjobs/TriggeredWebJob/run

Last step is to schedule it

Here we have selected it to run immediately, every 2 minutes for total of 10 occurrences.


Finally click on Create which will create the job


We can monitor our Job



Going back to our Web Job Logs we can see it ran 3 times with interval of 2 minutes till that point


The other option to schedule a Web Job without using Azure Scheduler is to use the Cron Job but this requires minimum Basic tier subscription. Basically, the Web App must be configured for “Always On”, which requires a Basic or Standard plan.

http://patrickdesjardins.com/blog/azure-webjobs-using-cronjobs

http://blog.amitapple.com/post/2015/06/scheduling-azure-webjobs/#.WNCQKDt9600

And in Free tier

https://www.schaeflein.net/azure-webjobs-free-tier/

Hope it helps..