Example #1
0
        public virtual async Task InitializeAsync(IVostokHostingEnvironment environment)
        {
            var log = environment.Log.ForContext <VostokAspNetCoreApplication>();

            var builder = new VostokAspNetCoreApplicationBuilder <TStartup>(environment, this, disposables);

            builder.SetupPingApi(
                settings =>
            {
                settings.CommitHashProvider  = GetCommitHash;
                settings.InitializationCheck = () => initialized;

                if (environment.HostExtensions.TryGet <IVostokApplicationDiagnostics>(out var diagnostics))
                {
                    settings.HealthCheck = () => diagnostics.HealthTracker.CurrentStatus == HealthStatus.Healthy;
                }
            });

            Setup(builder, environment);

            disposables.Add(manager = new HostManager(builder.BuildHost(), log));

            await manager.StartHostAsync(environment.ShutdownToken);

            await WarmupAsync(environment, manager.Services);

            await WarmupMiddlewares(environment);

            initialized.TrySetTrue();
        }
        public async Task InitializeAsync(IVostokHostingEnvironment environment)
        {
            var log = environment.Log.ForContext <VostokAspNetCoreApplication>();

            var builder = new VostokAspNetCoreApplicationBuilder <TStartup>(environment, disposables);

            builder.SetupPingApi(
                settings =>
            {
                settings.InitializationCheck = () => initialized;
                settings.CommitHashProvider  = GetCommitHash;
            });

            Setup(builder, environment);

            disposables.Add(manager = new HostManager(builder.BuildHost(), log));

            await manager.StartHostAsync(environment.ShutdownToken);

            await WarmupAsync(environment, manager.Services);

            initialized.TrySetTrue();
        }
Example #3
0
        private async Task WarmupMiddlewares(IVostokHostingEnvironment environment, VostokAspNetCoreApplicationBuilder <TStartup> builder)
        {
            if (environment.ServiceBeacon.ReplicaInfo.TryGetUrl(out var url))
            {
                var client = new ClusterClient(
                    environment.Log,
                    configuration =>
                {
                    configuration.ClusterProvider = new FixedClusterProvider(url);
                    configuration.SetupUniversalTransport();
                    configuration.SetupDistributedTracing(environment.Tracer);
                });

                if (builder.IsMiddlewareEnabled <PingApiMiddleware>())
                {
                    await client.SendAsync(Request.Get("_status/ping"), 20.Seconds());
                }
            }
            else
            {
                environment.Log.Warn("Unable to warmup middlewares. Couldn't obtain replica url.");
            }
        }