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?
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.