3
votes

I've been creating an Azure WebJob, it works aparently fine but I need to create a new function and I need test locally before upload to production site, I run on Debug the console program and this recognize all functions but I can't trigger any function.

Documentation say next trigger is every minute.... (https://github.com/Azure/azure-webjobs-sdk-extensions#timertrigger)

My code:

public static async void ProcessAugustEndowments([TimerTrigger("0 */1 * * * *", RunOnStartup = true)] TimerInfo timerInfo)
    {
        Console.WriteLine("Endowments process tried");

        await endowmentNotification();
    }

Output: Output example

2
One simple solution... write some code to manually call ProcessAugustEndowments from your Main() method. Comment or #ifdef around the host.RunAndBlock() method I expect you have.Dean Goodman
Is it only one function that is not working or all functions with TimerTrigger ? did you configure your jobhost to use timers config.UseTimers();?Thomas
No, I have some many functions with another TimerTriggers and yes this configure is on my WebJobCami Rodriguez
@DeanGoodman you can also call the webjob funcion directly itself on the Main method of the Program class of the Job project.Ulysses Alves

2 Answers

1
votes

I run on Debug the console program and this recognize all functions but I can't trigger any function.

Based on your code, I tested it on my side and found that when my firstly debug the application, then I could get the following output:

enter image description here

But, when I restarted the application, I found that it would take some time for the function to be triggered.

Please make sure that you have installed the latest version packages of "Microsoft.Azure.WebJobs" and "Microsoft.Azure.WebJobs.Extensions". For more details, you could follow this tutorial.

And please try to reduce the time interval in your TimerTrigger and wait for a period when the job host has started, then try to find out whether the function could be triggered on your side. Here is my code sample, you could refer to it.

Program.cs

static void Main()
{
    JobHostConfiguration config = new JobHostConfiguration();
    // Add Triggers and Binders for Timer Trigger.
    config.UseTimers();
    JobHost host = new JobHost(config);
    //host.RunAndBlock();
    host.Start();
    Console.WriteLine("[{0}] Job Host started!!!", DateTime.Now);
    Console.ReadLine();
}

Function.cs

//Function triggered by a timespan schedule every 5 sec.
public static async void ProcessAugustEndowments([TimerTrigger("*/5 * * * * *", RunOnStartup = true)] TimerInfo timerInfo)
{
    Console.WriteLine("Endowments process tried");
    await endowmentNotification();
}

private static async Task endowmentNotification()
{   
    //sleep for 2 sec to simulate processing business logic
    await Task.Delay(TimeSpan.FromSeconds(2));
}

Additionally, if the TimerTrigger could not meet your requirement, you could refer to this official tutorial to create a schedule WebJob, also you could refer to this blog.

1
votes

If your functions are not triggered, I presume it is because you didn't configure your JobHost you use TimerTrigger:

var config = new JobHostConfiguration();
config.UseTimers();

How the JobHost works with Triggers :

  • When the JobHost starts, it discovers and indexes the functions with some *TriggerAttribute.

  • By Specifying the config.UseTimers(); you tell to the JobHost to index functions with TimerTriggerAttribute.

This is also valid for others types of triggers like ServiceBusTrigger that need config.UseServiceBus() to work