question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Graceful Shutdown for Triggered Webjob with only NoAutomaticTrigger

See original GitHub issue

.NET Core 2.2 Webjobs SDK 3.0.10

I am trying to figure out a way I can do a graceful shutdown of my triggered webjob when i manually restart app service, or it is automatically restarted/recycled. I have only a single function decorated with [NoAutomaticTrigger] called like this. This is a long running job for many hours, and there are things i would like to do before it is forcibly stopped.

            using (host)
            {
                await host.StartAsync();
                var jobHost = host.Services.GetService<IJobHost>();
                await jobHost.CallAsync(nameof(Functions.ProcessData));
                await host.StopAsync();
            }

here is my function

        [Singleton]
        [FunctionName(nameof(ProcessData))]
        [NoAutomaticTrigger]
        public async Task ProcessData(ILogger logger, CancellationToken cancellationToken)
        {
                cancellationToken.Register(() =>
                {
                    logger.LogInformation("cancelled!");
                    Console.WriteLine("cancelled");
                });

                while (!cancellationToken.IsCancellationRequested)
                {
                    await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
                    logger.LogInformation("waiting");
                }
                logger.LogInformation("escaped");
        }

i monitor the cancellation token, register a function when cancelled, but it doesn’t appear to be working. Function gets stuck in “waiting” loop I’m not sure if this is just not a supported scenario, or I’m doing something wrong. All the documentation around graceful shutdown i see seems to be around continuous webjobs.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
czb182commented, Jan 23, 2020

No. I put in the code as I thought it should work, hoping that a future library update will make it work. Unfortunately there is not a lot of activity in this repo, so not sure if/when that would happen

0reactions
msftbot[bot]commented, Oct 12, 2020

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notification of when continuous Azure WebJob is stopping ...
the graceful shutdown goes in the Startup.cs : public class Startup { [NoAutomaticTrigger] public static void Start(TextWriter log) { var ...
Read more >
How to use the WebJobs SDK - Azure App Service
For information about how to handle cancellation tokens, see the Azure Functions documentation on cancellation tokens and graceful shutdown.
Read more >
WebJobs Graceful Shutdown - Blog.Amit Apple
For triggered WebJobs there is no shutdown notification but there is a graceful period (30 seconds by default) where the WebJob will not...
Read more >
Notification of when continuous Azure ... - appsloveworld.com
the graceful shutdown goes in the Startup.cs : public class Startup { [NoAutomaticTrigger] public static void Start(TextWriter log) { var token = new ......
Read more >
Avoid un-stoppable webjobs using JobHost - Stuff & Tacos
We started usage of Azure continuous webjobs due to the flexibility in ... RunAndBlock() will block the main thread; gracefully shutdown for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found