Hangfire now dies gracefully when using CTRL+C rather than Stop button in Rider. Implemented one stream method for testing. Regenerated a few migrations due to oversight in index not taking account of library.
This commit is contained in:
parent
126fb57f4d
commit
9035b6cc4e
17 changed files with 156 additions and 41 deletions
|
|
@ -18,6 +18,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
|||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using IApplicationLifetime = Microsoft.AspNetCore.Hosting.IApplicationLifetime;
|
||||
|
||||
namespace API
|
||||
{
|
||||
|
|
@ -66,11 +67,11 @@ namespace API
|
|||
services
|
||||
.AddStartupTask<WarmupServicesStartupTask>()
|
||||
.TryAddSingleton(services);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IWebHostEnvironment env)
|
||||
public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IWebHostEnvironment env, IHostApplicationLifetime applicationLifetime)
|
||||
{
|
||||
app.UseMiddleware<ExceptionMiddleware>();
|
||||
|
||||
|
|
@ -125,6 +126,16 @@ namespace API
|
|||
endpoints.MapHangfireDashboard();
|
||||
endpoints.MapFallbackToController("Index", "Fallback");
|
||||
});
|
||||
|
||||
applicationLifetime.ApplicationStopping.Register(OnShutdown);
|
||||
}
|
||||
|
||||
private void OnShutdown()
|
||||
{
|
||||
Console.WriteLine("Server is shutting down. Going to dispose Hangfire");
|
||||
//this code is called when the application stops
|
||||
//TaskScheduler.Client.Dispose();
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue