Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run an Azure WebJob locally?

I want to create a continuously running WebJob but first I want to try and run it locally for debugging. I am using Visual Studio 2015 and I have the Azure storage emulator running (I can run the sample for Azure WebJobs in visual studio).

When I run the below it fails on the new JobHost() line with:

Exception: Value cannot be null. Parameter name: method

    static void Main()
    {
        var host = new JobHost();
        host.CallAsync(typeof(Functions).GetMethod("GetNextJob"));
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }
    [NoAutomaticTriggerAttribute]
    public static async Task GetNextJob()
    {
        while(true)
        {
            try
            {
                var log = new Logger();
                log.WriteInfo("Getting next job to be run", 0, 0, "Brain");
                //Console.WriteLine("Getting new Job and putting to que");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            await Task.Delay(TimeSpan.FromSeconds(5));
        }
    }

Can I even run the continous running jobs locally?

like image 635
DanScan Avatar asked Oct 18 '15 20:10

DanScan


People also ask

How do I publish my Azure WebJob?

In Solution Explorer, right-click the project and select Publish. In the Publish dialog box, select Azure for Target, and then select Next. Select Azure WebJobs for Specific target, and then select Next. Above App Service instances select the plus (+) button to Create a new Azure WebJob.

How do I debug Azure WebJob in Visual Studio?

Visual Studio deploys the web and WebJob projects, and your browser opens to the Azure URL of your web app. In Server Explorer expand Azure > App Service > your resource group > your web app > WebJobs > Continuous, and then right-click ContosoAdsWebJob. Click Attach Debugger.


1 Answers

Azure WebJobs are typically just console applications. You can run it locally just like you would debug, test and run any other console application. I'd recommend getting the Azure WebJobs SDK and running through the tutorial Create a .NET WebJob in Azure App Service.

like image 200
viperguynaz Avatar answered Sep 30 '22 05:09

viperguynaz