Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console(new RenderedCompactJsonFormatter())
                         .Enrich.FromLogContext()
                         .CreateLogger();

            // See https://support.microsoft.com/en-gb/help/821268/contention-poor-performance-and-deadlocks-when-you-make-calls-to-web-s
            ThreadPool.SetMaxThreads(100, 100);
            ThreadPool.SetMinThreads(50, 50);

            Parser.Default.ParseArguments <DeploymentPoolArgs>(args)
            .WithParsed(parsedArgs =>
            {
                parsedArgs.Validate();
                var spatialRefreshToken = Environment.GetEnvironmentVariable(SpatialRefreshTokenEnvironmentVariable) ??
                                          throw new Exception(
                    $"{SpatialRefreshTokenEnvironmentVariable} environment variable is required.");
                if (spatialRefreshToken == "")
                {
                    throw new ArgumentException("Refresh token should not be empty");
                }

                IAnalyticsSender analyticsSender = new AnalyticsSenderBuilder("deployment_pool")
                                                   .WithCommandLineArgs(parsedArgs)
                                                   .With(new LogExceptionStrategy(Log.Logger))
                                                   .Build();

                var spatialDeploymentClient =
                    DeploymentServiceClient.Create(credentials: new PlatformRefreshTokenCredential(spatialRefreshToken));
                var spatialSnapshotClient =
                    SnapshotServiceClient.Create(credentials: new PlatformRefreshTokenCredential(spatialRefreshToken));
                var platformInvoker = new PlatformInvoker(parsedArgs, spatialDeploymentClient, spatialSnapshotClient, analyticsSender);


                var cancelTokenSource = new CancellationTokenSource();
                var cancelToken       = cancelTokenSource.Token;

                var metricsServer  = new MetricServer(parsedArgs.MetricsPort).Start();
                var dplPool        = new DeploymentPool(parsedArgs, spatialDeploymentClient, platformInvoker, cancelToken, analyticsSender);
                var dplPoolTask    = Task.Run(() => dplPool.Start());
                var unixSignalTask = Task.Run(() => UnixSignal.WaitAny(new[] { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGTERM) }));
                Task.WaitAny(dplPoolTask, unixSignalTask);

                if (unixSignalTask.IsCompleted)
                {
                    Log.Information($"Received UNIX signal {unixSignalTask.Result}");
                    Log.Information("Server shutting down...");
                    cancelTokenSource.Cancel();
                    metricsServer.StopAsync();
                    dplPoolTask.Wait();
                    Log.Information("Server stopped cleanly");
                }
                else
                {
                    /* The server task has completed; we can just exit. */
                    Log.Information($"The deployment pool has stopped itself or encountered an unhandled exception {dplPoolTask.Exception}");
                }
            });
        }
 public DeploymentPool(
     DeploymentPoolArgs args,
     DeploymentServiceClient deploymentServiceClient,
     PlatformInvoker platformInvoker,
     CancellationToken token)
 {
     cancelToken             = token;
     matchType               = args.MatchType;
     spatialProject          = args.SpatialProject;
     minimumReadyDeployments = args.MinimumReadyDeployments;
     cleanup = args.Cleanup;
     this.platformInvoker         = platformInvoker;
     this.deploymentServiceClient = deploymentServiceClient;
 }
Exemplo n.º 3
0
 public DeploymentPool(
     DeploymentPoolArgs args,
     DeploymentServiceClient deploymentServiceClient,
     PlatformInvoker platformInvoker,
     CancellationToken token,
     IAnalyticsSender analytics = null)
 {
     cancelToken             = token;
     matchType               = args.MatchType;
     spatialProject          = args.SpatialProject;
     minimumReadyDeployments = args.MinimumReadyDeployments;
     cleanup = args.Cleanup;
     this.platformInvoker         = platformInvoker;
     this.deploymentServiceClient = deploymentServiceClient;
     _analytics = (analytics ?? new NullAnalyticsSender()).WithEventClass("deployment");
 }