Reputation: 53
I'm new at the Azure Webjob concept. I'm trying to create a WebJob which will be triggered.
Program.cs
static void Main()
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
host.Call(typeof(Functions).GetMethod("MyMethod"));
host.RunAndBlock();
}
Function.cs
[NoAutomaticTrigger]
public static void MyMethod()
{
//Logic
}
I can see that My WebJob is running, but only invoking the function at the very beginning of the deployment. I can run the function via using Function Invocation Log.
If I'm not mistaken it should invoke the function as I scheduled right?
Upvotes: 0
Views: 473
Reputation: 16801
You are triggering the job at startup with this line host.RunAndBlock();
If you want it to be triggered by a schedule,
just add a settings.job
file to your webjob project containing the cron time you want
For example
{
"schedule": "0 0 * * * *"
}
Then in you program.cs, just use
using (var host = new JobHost(config))
{
host.Call(typeof(Functions).GetMethod("MyMethod"));
}
Deploy the code, don't forget to copy the settings.job
to your output directory, and the cron setting should be visual under your application webjob view from the portal
Upvotes: 2
Reputation: 15571
If I'm not mistaken it should invoke the function as I scheduled right?
What schedule? You didn't configure any schedule. The only thing you're doing is calling MyMethod
once (by getting the method using reflection!) and then you're calling RunAndBlock
on host
.
Have a look at Run Background tasks with WebJobs in Azure App Service > Create a scheduled WebJob
You could have a look at Azure Functions. That might help, too.
Upvotes: 0