Пример #1
0
        private void StartDeployment(string deploymentName, int retries = 0)
        {
            var launchConfig = new LaunchConfig
            {
                ConfigJson = Utils.GetFileContent(WorkerType, launchConfigFile),
            };

            var snapshotId = DeploymentModifier.UploadSnapshot(workerConfig.ProjectName, deploymentName);
            var template   = new DeploymentTemplate
            {
                AssemblyId     = sessionConfig.AssemblyName,
                DeploymentName = deploymentName,
                LaunchConfig   = launchConfig,
                ProjectName    = workerConfig.ProjectName,
                SnapshotId     = snapshotId,
                RegionCode     = sessionConfig.RegionCode,
            };

            Log.Print(LogLevel.Info, $"Creating deployment {deploymentName}.", serviceConnection);
            var deploymentOperation = DeploymentModifier.CreateDeployment(template).PollUntilCompleted();

            if (deploymentOperation.IsCompleted)
            {
                Log.Print(LogLevel.Info, $"Successfully created deployment {deploymentName}.", serviceConnection);
                ConnectToDeployment(deploymentOperation.Result);
            }
            else if (deploymentOperation.IsFaulted)
            {
                Log.Print(LogLevel.Error, $"Failed to create deployment {deploymentName} with exception {deploymentOperation.Exception}. " +
                          $"Trying again.", serviceConnection);

                if (retries < Utils.MaxRetries)
                {
                    Task.Run(() => StartDeployment(deploymentName, retries + 1));
                }
            }
        }
        public static Google.LongRunning.Operation <Deployment, CreateDeploymentMetadata> CreateDeployment(DeploymentTemplate template)
        {
            var request = new CreateDeploymentRequest
            {
                Deployment = template.ToDeployment()
            };

            return(ExceptionHandler.HandleGrpcCall(() => deploymentServiceClient.CreateDeployment(request)));
        }