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:
- Created 4 years ago
- Comments:12 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.