Rem
Rem

Reputation: 73

Azure timertriggered webjob hangs randomly

I want to schedule a timertriggered method to call other methods but somehow the CronJob method won't run if I use it to call one of my own methods, I simply get this console output: " Found the following functions: ...ProcessQueueMessage ...Functions.CronJob Job host started "

and nothing else happens for a couple of minutes and then it might suddenly start working. But if I only use the CronJob() method for running it's own Console.WriteLine("Timer job fired") statement everything works.

I have been trying to find a solution to this problem for hours now but no one seems to have the same problem. Any ideas on what I'm doing wrong?

public static void CronJob([TimerTrigger("*/3 * * * * *", RunOnStartup = true)] TimerInfo timerInfo)
    {
        Console.WriteLine("Timer job fired! ");
        DoTask();

    }

    private static void DoTask()
    {
        Console.WriteLine("Doing task...");
    }

Main method:

static void Main()
    {
        var config = new JobHostConfiguration();

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }

        var host = new JobHost(config);
        config.UseTimers();
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }

Upvotes: 2

Views: 732

Answers (1)

Tom Sun
Tom Sun

Reputation: 24549

Any ideas on what I'm doing wrong?

According to your description, it is not related with whether you call code directly. The root reason is that a blob lease (the Singleton Lock) is taken for a default time of 30 seconds.

As Rob Reagan mention that you could set JobHostConfiguration.Tracing.ConsoleLeve to Verbose. When the webjob hangs you could get the information "Unable to aquire Singleton lock".

For more detail info you could refer to this issue.

When the listener starts for a particular TimerTrigger function, a blob lease (the Singleton Lock) is taken for a default time of 30 seconds. This is the lock that ensures that only a single instance of your scheduled function is running at any time. If you kill your console app, that lease will still be held until it expires naturally

Upvotes: 3

Related Questions