Search code examples
azureazure-functionsazure-webjobsazure-webjobssdk

Azure Web Job always Failed


I have this Azure WebJob function that runs every Saturday. But the Azure function always tagged as Failed but the Job runs successfully when finished as I checked the log.

Already increase WEBJOBS_IDLE_TIMEOUT and SCM_COMMAND_IDLE_TIMEOUT in Configuration but still tagged as Failed. But still got this error.

Command 'cmd /c ""Software.. ...' 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.

The number of data to be processed is unpredictable, it depends the number of users inputted the values, so the processing time would be between 1 to 40 minutes, 1 minute for least data and 40 minutes for larger data.

I'm currently using the latest version of WebJob SDK.

Image

Here's the code snippet.

public class ProcessDataFunction
{
    private readonly IProcessData _processData;

    public ProcessDataFunction(IProcessData processData)
    {
        _processData = processData;
    }

    [Singleton]
    public async Task ProcessDataMessage([TimerTrigger("0 0 12 * * 6", RunOnStartup = true)] TimerInfo myTimer, ILogger logger, CancellationToken cancellationToken)
    {
        logger.LogInformation("Long running Job Started...");

        var dateSync = DateTimeOffset.UtcNow;

        await _processData.ProcessAsync(cancellationToken, dateSync);

       logger.LogInformation("Long running Job Finished...");
    }
}

class Program
{
    static async Task Main()
    {
        var builder = new HostBuilder();
        builder.ConfigureWebJobs(b =>
        {
            b.AddTimers();
            b.AddAzureStorageCoreServices();

        });
        builder.ConfigureLogging((context, b) =>
        {
            b.AddConsole();
        });
        builder.ConfigureServices((context, services) =>
        {
            services.ConfigureHttpClients(context.Configuration)
                .ConfigureDataProcessor()
                .ConfigureDbContext(context.Configuration);
        });
        
        var host = builder.Build();
        using (host)
        {
            await host.RunAsync();
        }
    }

}

Solution

  • Just to confirm if you have enabled Always on setting? As mentioned in the document:

    A web app can time out after 20 minutes of inactivity, and only requests to the actual web app can reset the timer. Viewing the app's configuration in the Azure portal or making requests to the advanced tools site (https://<app_name>.scm.azurewebsites.net) doesn't reset the timer. If you set your web app to run continuously, run on a schedule, or use event-driven triggers, enable the Always on setting on your web app's Azure Configuration page. The Always on setting helps to make sure that these kinds of WebJobs run reliably. This feature is available only in the Basic, Standard, and Premium pricing tiers.

    Also suggest you for triggered jobs in your Program.cs, try to replace host.Run(); by host.Start();

    Further you may also refer to this blog might helps.