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:
Praburaj 2014-09-19 13:49:42 -07:00
parent 7eb78b8dd1
commit 3ce74b6c4e
1 changed files with 22 additions and 0 deletions

View File

@ -19,6 +19,8 @@ using MusicStore.Mocks.Common;
using MusicStore.Mocks.Facebook;
using MusicStore.Mocks.Twitter;
using MusicStore.Mocks.Google;
using Microsoft.Framework.Runtime;
using System.Threading.Tasks;
namespace MusicStore
{
@ -88,6 +90,26 @@ namespace MusicStore
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
app.UseSignalR();