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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With