Azure web job keep restarting

608 views Asked by At

I've created a console application that I run as a continuous web job. It does not use the web job SDK, but it checks for the file specified in the WEBJOBS_SHUTDOWN_FILE environment variable.

I have turned the 'Always On' option on, and I'm running the job in the shared plan as a singleton using the settings.job file.

The web job keeps getting stopped by the WEBJOBS_SHUTDOWN_FILE and is restarted again after that.

I've been looking in the kudu sources, but I can't find why my web job is restarted.

Does anybody have an idea why this happens?

This is the code that initializes the FileSystemWatcher:

private void SetupExitWatcher()
{
    var file = Environment.GetEnvironmentVariable("WEBJOBS_SHUTDOWN_FILE");
    var dir = Path.GetDirectoryName(file);
    var fileSystemWatcher = new FileSystemWatcher(dir);

    FileSystemEventHandler changed = (o, e) =>
    {
        if (e.FullPath.Equals(Path.GetFileName(file), StringComparison.OrdinalIgnoreCase) >= 0)
        {
            this.Exit();
        }
    };

    fileSystemWatcher.Created += changed;
    fileSystemWatcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.FileName | NotifyFilters.LastWrite;
    fileSystemWatcher.IncludeSubdirectories = false;
    fileSystemWatcher.EnableRaisingEvents = true;
}
0

There are 0 answers