Adding a way to do a graceful shutdown of the server.
This code path is not being used right now as there is no way to select this start up class.
This commit is contained in:
parent
7eb78b8dd1
commit
3ce74b6c4e
|
|
@ -19,6 +19,8 @@ using MusicStore.Mocks.Common;
|
||||||
using MusicStore.Mocks.Facebook;
|
using MusicStore.Mocks.Facebook;
|
||||||
using MusicStore.Mocks.Twitter;
|
using MusicStore.Mocks.Twitter;
|
||||||
using MusicStore.Mocks.Google;
|
using MusicStore.Mocks.Google;
|
||||||
|
using Microsoft.Framework.Runtime;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MusicStore
|
namespace MusicStore
|
||||||
{
|
{
|
||||||
|
|
@ -88,6 +90,26 @@ namespace MusicStore
|
||||||
services.AddInstance<IMemoryCache>(new MemoryCache());
|
services.AddInstance<IMemoryCache>(new MemoryCache());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//To gracefully shutdown the server - Not for production scenarios
|
||||||
|
app.Map("/shutdown", shutdown =>
|
||||||
|
{
|
||||||
|
shutdown.Run(async context =>
|
||||||
|
{
|
||||||
|
var appShutdown = context.ApplicationServices.GetService<IApplicationShutdown>();
|
||||||
|
appShutdown.RequestShutdown();
|
||||||
|
|
||||||
|
await Task.Delay(10 * 1000, appShutdown.ShutdownRequested);
|
||||||
|
if (appShutdown.ShutdownRequested.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
await context.Response.WriteAsync("Shutting down gracefully");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await context.Response.WriteAsync("Shutting down token not fired");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//Configure SignalR
|
//Configure SignalR
|
||||||
app.UseSignalR();
|
app.UseSignalR();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue