Search code examples
azureazure-webjobs-triggered

Why does my Time trigger webjob keep running?


I have a Webjob that I want to be time triggered:

public class ArchiveFunctions
{
    private readonly IOrderArchiver _orderArchiver;

    public ArchiveFunctions(IOrderArchiver orderArchiver)
    {
        _orderArchiver = orderArchiver;
    }

    public async Task Archive([TimerTrigger("0 */5 * * * *")] TimerInfo timer, TextWriter log)
    {
            log.WriteLine("Hello world");
    }
}

My program.cs:

public static void Main()
    {
        var config = new JobHostConfiguration
        {
            JobActivator = new AutofacJobActivator(RegisterComponents())
        };

        config.UseTimers();

        var host = new JobHost(config);

        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();

    }

my publish-setting.json:

{
  "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName": "OrdersArchiving",
  "runMode": "OnDemand"
}

Here is what it looks like on azure portal: enter image description here

My problem is that the job runs, I have the hello world, but the job keeps in run state and it get to a time out error message:

[02/05/2018 15:34:05 > f0ea5f: ERR ] Command 'cmd /c ""Ores.Contr ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.

What can I do to fix this? I have a wild guess RunAndBlock could be a problem.. but I do not see a solution.. Thanks!

Edit:

I have tested Rob Reagan answer, it does help with the error, thank you! On my same service, I have one other time triggerd job (was done in core, while mine is not). enter image description here

You can see the Webjob.Missions is 'triggered', and status update on last time it ran. You can see as well the schedule on it. I would like to have the same for mine 'OrdersArchiving'. How can I achieve that? Thanks!


Solution

  • Change your run mode to continuous and not triggered. The TimerTrigger will handle executing the method you've placed it on.

    Also, make sure that you're not using a Free tier for hosting your WebJob. After twenty minutes of inactivity, the app will be paused and will await a new HTTP request to wake it up.

    Also, make sure you've enabled Always On on your Web App settings to prevent the same thing from happening to a higher service tier web app.

    Edit Tom asked how to invoke methods on a schedule for a Triggered WebJob. There are two options to do so:

    1. Set the job up as triggered and use a settings.json file to set up the schedule. You can read about it here.

    2. Invoke a method via HTTP using an Azure Scheduler. The Azure Scheduler is a separate Azure service that you can provision. It has a free tier which may be sufficient for your use. Please see David Ebbo's post on this here.