private void OnStopping() { _logger.LogInformation("Stopping host..."); if (_host != null) { _host.StopAsync().Wait(); } }
static async Task StopSilo() { await silo.StopAsync(); _siloStopped.Set(); Console.WriteLine("Silo stopped - program should exit now."); }
private static async Task <int> MainInternal(string[] args) { int result = 0; try { // Server will be able to load any referenced (as a project) Grain automatically. // If it does not, then most likely some Orleans package is missing. Console.WriteLine("Starting worker silo..."); ISiloHost siloHost = await StartSilo(); Console.WriteLine("Worker Silo started and waiting for tasks!"); _exitEvent.WaitOne(); CancellationTokenSource exit = new CancellationTokenSource(TimeSpan.FromMilliseconds(EXIT_TIMEOUT)); // TODO Seems that silo host is inclinable to hang on 'StopAsync'. // Needs to be investigated. try { // When the cancelation token fires the silo is expected to exit ungracefully. await siloHost.StopAsync(exit.Token); } catch (Exception exc) { Console.WriteLine(exc.Message); result = -1; } } catch (Exception exc) { Console.WriteLine(exc.Message); result = -1; } return(result); }
public async Task StopAsync(CancellationToken cancellationToken) { if (_host != null) { await _host.StopAsync(); } }
public static async Task <int> Main(string[] args) { ISiloHost host = null; try { host = await StartSiloHostAsync(); return(0); } catch (Exception e) { Console.WriteLine(e); return(1); } finally { Console.WriteLine("Press Enter to terminate..."); Console.ReadKey(); if (host != null) { await host.StopAsync(); } } }
private static async Task StopSilo(ISiloHost siloHost, ILogger logger) { await siloHost.StopAsync(); SiloStopped.Set(); logger.LogInformation("Silo stopped."); }
static async Task Main(string[] args) { using (SentrySdk.Init(Dsn)) { ISiloHostBuilder siloBuilder = new SiloHostBuilder() .UseLocalhostClustering() .AddMemoryGrainStorageAsDefault() .AddStartupTask( (provider, token) => provider.GetRequiredService <IGrainFactory>() .GetGrain <IGame>(0) .InitGame(true)) .ConfigureAppConfiguration( (context, configure) => configure .AddJsonFile( "appsettings.json", optional: false) .AddJsonFile( $"appsettings.{context.HostingEnvironment}.json", optional: true) .AddEnvironmentVariables() .AddCommandLine(args)) .ConfigureServices(Configure); ISiloHost silo = siloBuilder.Build(); await silo.StartAsync(); var closeEvent = new AutoResetEvent(false); Console.CancelKeyPress += (sender, e) => { closeEvent.Reset(); }; closeEvent.WaitOne(); silo.Services.GetService <ILogger <Program> >().LogInformation("stopping"); await silo.StopAsync(); } }
private static async Task StopSilo() { await _silo.StopAsync(); Trace.WriteLine("Silo stopped"); _siloStopped.Set(); }
public void Stop() { if (_serviceArguments == null) { return; } var cancelAfter = new CancellationTokenSource(TimeSpan.FromSeconds(_serviceArguments.OnStopWaitTimeSec.Value)).Token; try { HttpServiceListener?.Dispose(); } catch (Exception e) { Log.Warn((m) => m("Failed to close HttpServiceListener ", exception: e)); } try { _siloHost?.StopAsync(cancelAfter).Wait(cancelAfter); _siloHost?.Dispose(); } catch (Exception e) { Log.Error((m) => m(" Silo failed to StopAsync", exception: e)); } }
static async Task Main(string[] args) { Serializers.RegisterAll(); var configBuilder = new ConfigurationBuilder(); ConfigureAppConfiguration(configBuilder); Configuration = configBuilder.Build(); SelectAssemblies(); var builder = new SiloHostBuilder() .ConfigureLogging(ConfigureLogging) .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "MineCaseService"; }) .Configure <SchedulingOptions>(options => { options.AllowCallChainReentrancy = true; options.PerformDeadlockDetection = true; }) .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000) .AddSimpleMessageStreamProvider("JobsProvider") .AddSimpleMessageStreamProvider("TransientProvider") .UseMongoDBReminders(options => { options.ConnectionString = Configuration.GetSection("persistenceOptions")["connectionString"]; }) .UseMongoDBClustering(c => { c.ConnectionString = Configuration.GetSection("persistenceOptions")["connectionString"]; // c.UseJsonFormat = true; }) .ConfigureApplicationParts(ConfigureApplicationParts) .UseDashboard(options => { }) .UseServiceProviderFactory(ConfigureServices); MongoDBSiloExtensions.AddMongoDBGrainStorageAsDefault(builder, options => { options.ConnectionString = Configuration.GetSection("persistenceOptions")["connectionString"]; }); MongoDBSiloExtensions.AddMongoDBGrainStorage(builder, "PubSubStore", options => { options.ConnectionString = Configuration.GetSection("persistenceOptions")["connectionString"]; }); // ConfigureApplicationParts(builder); _siloHost = builder.Build(); await StartAsync(); Console.WriteLine("Press Ctrl+C to terminate..."); Console.CancelKeyPress += (s, e) => _exitEvent.Set(); _exitEvent.WaitOne(); Console.WriteLine("Stopping..."); await _siloHost.StopAsync(); await _siloHost.Stopped; Console.WriteLine("Stopped."); }
private static void StopSilo() { _log.Information("Stopping orleans silo host"); _silo.StopAsync().GetAwaiter().GetResult(); _silo.Dispose(); _log.Information("Orleans silo host stopped"); }
static async Task Main(string[] args) { Serializers.RegisterAll(); var configBuilder = new ConfigurationBuilder(); ConfigureAppConfiguration(configBuilder); Configuration = configBuilder.Build(); var builder = new SiloHostBuilder() .ConfigureLogging(ConfigureLogging) .UseConfiguration(LoadClusterConfiguration()) .UseServiceProviderFactory(ConfigureServices); SelectAssemblies(); ConfigureApplicationParts(builder); _siloHost = builder.Build(); await StartAsync(); Console.WriteLine("Press Ctrl+C to terminate..."); Console.CancelKeyPress += (s, e) => _exitEvent.Set(); _exitEvent.WaitOne(); Console.WriteLine("Stopping..."); await _siloHost.StopAsync(); await _siloHost.Stopped; Console.WriteLine("Stopped."); }
public static async Task <int> LogAndRun(ISiloHost siloHost) { Log.Logger = BuildLogger(siloHost.Services.GetRequiredService <IConfiguration>()); try { Log.Information("Starting application."); await siloHost.StartAsync(); Log.Information("Started application"); Console.Read(); Log.Information("Stopping application"); await siloHost.StopAsync(); Log.Information("Stopped application"); return(0); } catch (Exception exception) { Log.Fatal(exception, "Application terminated unexpectedly"); return(1); } finally { Log.CloseAndFlush(); } }
private static async Task StopSilo() { await silo.StopAsync(); Console.WriteLine("Silo stopped"); siloStopped.Set(); }
public async Task Shutdown() { await _client.Close(); await _secondarySilo.StopAsync(); await _primarySilo.StopAsync(); }
private static async Task StopSilo() { await silo.StopAsync(); Console.ForegroundColor = color; Console.WriteLine("Silo Stopped at {0}", DateTime.Now); Console.ResetColor(); }
public async Task StopAsync(CancellationToken cancellationToken) { startupException?.Throw(); logger.LogInformation("Stopping Orleans Silo"); await siloHost.StopAsync(cancellationToken).ConfigureAwait(false); logger.LogInformation("Orleans Silo stopped."); }
public async Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("Stopping Orleans cluster."); await _siloClient.Close(); await _siloHost.StopAsync(); _logger.LogInformation("Orleans cluster has stopped."); }
public async Task CleanupTest() { if (_host != null) { await _host.StopAsync().ConfigureAwait(false); _host.Dispose(); _host = null; } }
public void Dispose() { _clusterClient?.Close(); _clusterClient?.Dispose(); _siloHost?.StopAsync().Wait(); _siloHost?.Dispose(); _siloScope?.Dispose(); }
//--------------------------------------------------------------------- private static async Task <int> RunMainAsync() { //var ucenter_context = new UCenterContext(); //await ucenter_context.Setup(); //var ucenter_cfg = ucenter_context.ConfigCfg; SetupApplicationShutdown(); var builder = new SiloHostBuilder() .Configure <ClusterOptions>(options => { options.ClusterId = "a"; options.ServiceId = "b"; }) .Configure <EndpointOptions>(options => { options.AdvertisedIPAddress = IPAddress.Loopback; options.GatewayPort = 30001; options.SiloPort = 11112; }) .Configure <StatisticsOptions>(options => { options.CollectionLevel = StatisticsLevel.Critical; }) .ConfigureApplicationParts(parts => { parts.AddApplicationPart(typeof(GrainAccount).Assembly).WithReferences(); }) .ConfigureLogging(logging => { logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true }); }) .UseLocalhostClustering() .UseSiloUnobservedExceptionsHandler() .UseInMemoryReminderService() .AddMemoryGrainStorageAsDefault() .AddMemoryGrainStorage("PubSubStore") .AddSimpleMessageStreamProvider("SMSProvider") .EnableDirectClient() .AddStartupTask <Startup>(); silo = builder.Build(); await silo.StartAsync(); _siloStopped.WaitOne(); await silo.StopAsync(); return(0); }
public async Task StopAsync(CancellationToken cancellationToken) { if (silo != null) { Console.WriteLine("Stopping silo..."); await silo.StopAsync(cancellationToken); await silo.Stopped; Console.WriteLine("Stopped gracefully"); } }
public void StopSilo() { try { m_SiloHost.StopAsync().Wait(); } catch (Exception ex) { Log.Debug(ex); } }
public async Task StopAsync(CancellationToken cancellationToken) { if (_siloHost != null) { await _siloHost.StopAsync(cancellationToken); await _siloHost.Stopped; _siloHost.Dispose(); //_scope.Dispose(); } }
public async Task StopAsync() { if (_silo == null) { throw new InvalidOperationException("Host is not started yet"); } await _silo.StopAsync(); _silo = null; }
private async void OnApplicationStopping() { _logger.LogInformation("stopping Orleans silo host..."); try { await _siloHost.StopAsync(); } catch (Exception ex) { _logger.LogError(ex, "Error when shutdown Silo Host"); } }
public static async Task <int> StopSilo() { try { await _siloHost.StopAsync(); return(0); } catch (Exception exc) { Console.WriteLine(exc); Console.WriteLine("Failure stopping silo."); return(1); } }
public static async Task <int> LogAndRun(ISiloHost siloHost) { Log.Logger = BuildLogger(siloHost.Services.GetRequiredService <IConfiguration>()); try { Log.Information("Starting application"); await siloHost.StartAsync(); Log.Information("Started application, press CTRL+C to exit"); var siloStopped = new ManualResetEvent(false); void OnCancelKeyPress(object sender, ConsoleCancelEventArgs e) { Console.CancelKeyPress -= OnCancelKeyPress; // Remove handler to stop listening to CTRL+C events. e.Cancel = true; // Prevent the application from crashing ungracefully. Task.Run(async() => // Shutdown gracefully on a background thread. { try { Log.Information("Stopping application"); await siloHost.StopAsync(); Log.Information("Stopped application"); siloStopped.Set(); } catch (Exception exception) { Log.Fatal(exception, "Application stopped ungracefully"); } }); } Console.CancelKeyPress += OnCancelKeyPress; siloStopped.WaitOne(); return(0); } catch (Exception exception) { Log.Fatal(exception, "Application terminated unexpectedly"); return(1); } finally { Log.CloseAndFlush(); } }
private static async Task <int> Main(string[] args) { string environmentName = Environment.GetEnvironmentVariable("SERVER_ENVIRONMENT"); Logger logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true, true) .AddJsonFile($"appsettings.{environmentName}.json", true) .AddEnvironmentVariables() .Build(); AppConfig config = new AppConfig(); configuration.Bind("AppConfig", config); try { if (config.MigrateDatabases) { EvolveMigrator migrator = new EvolveMigrator(); migrator.Migrate(config.ConnectionStrings[Constants.System], Constants.SystemScripts, false); } logger.Info("Rialto Silo has been started"); ISiloHost host = await StartSilo(config); Console.WriteLine("Enter 'exit' to stop..."); while (!(Console.ReadLine() ?? string.Empty).Equals("exit")) { } await host.StopAsync(); logger.Info("Rialto Silo has been stopped"); return(0); } catch (Exception ex) { logger.Error(ex, "Rialto Silo is failed"); } finally { LogManager.Shutdown(); } return(-1); }
public static IDisposable Run(this ISiloHost siloHost) { if (siloHost == null) { throw new ArgumentNullException(nameof(siloHost)); } siloHost.StartAsync().Wait(); return(new AnonymousDisposable(() => { if (!siloHost.Stopped.IsCompleted) { siloHost.StopAsync().Wait(); } })); }