Search code examples
azureazure-webjobsazure-webjobssdk

Azure WebJob Running after Deleted and Web App Stopped


We are testing a new WebJob to run some background processes in a Azure Web Service. The WebJob has a TimerTrigger and runs every 1 minute.

We are in early stages of development, so all the code does right now is log to our database every time it runs.

We saw records being inserted into our database so we deleted the WebJob to test a couple other things. We found that records continued to be inserted into the database after deleting the WebJob via the Portal. We proceeded to Stop the App Service entirely, but still records continued to be inserted into the database.

This SO post suggested checking for activity via the azure cli, however, an empty array is returned (same if we swap 'triggered' for 'continuous'):

az webapp webjob triggered list --name my-app-name --resource-group my-rg-name

The WebJob has been deleted & the Azure App Service has been stopped for about an hour now and still we are getting records inserted into the database every minute.

Our program is not much more complicated than the .NET Core examples offered here (GitHub Azure WebJobs SDK Extensions)

We have a simple Program.cs:

var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
    b.AddTimers();
});
builder.ConfigureLogging((context, b) =>
{
    b.AddConsole();
});

var host = builder.Build();
using (host)
{
    await host.RunAsync();
}

Functions.cs

public async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger logger)
{
    var connection = _db.Connection;
    await connection.ExecuteAsync("INSERT INTO webjob_logs VALUES ('test', GETDATE())");
}

Settings.job

{
  "schedule": "0 */1 * * * *"
}

Update

After redeploying the webjob & restarting the web app but it is still running the old code: WebJob from Azure Portal

Also, not sure if this is related, but I am seeing this in the WebJob Details: WebJob Details


Solution

  • We have few options to delete a running Web Job.

    One is manual deletion.

    And the other is by using Azure CLI command which you have already done by following my previous answer.

    And one more option is to delete the entire files which are uploaded while creating a Web Job.

    Whenever a Web Job is created a new folder with name Jobs will be created in KUDU Console site/wwwroot/App_Data folder.

    enter image description here

    • It contains all the Jobs with required exe/pdb/dll files related to the WebJob.

    enter image description here

    • Delete the entire folder with specific WebJob Name which you want to delete.

    Sometimes even after deleting the WebJobs, the jobs will be running in background without our Knowledge.

    As mentioned in the MSDoc, set the key WEBJOBS_STOPPED with value 1 in the App Service Application Settings to stop the WebJobs.

    enter image description here

    Thanks @IKriKan for the hint.

    If you still have any issues with the Web Jobs, you can check the Job details in Diagnose and solve problems => Availability and Performance => WebJob Details

    enter image description here