예제 #1
0
        public async Task StartWorkerAsync(DFrameOptions options, int processCount, IServiceProvider provider, IFailSignal failSignal, CancellationToken cancellationToken)
        {
            _failSignal = failSignal;

            Console.WriteLine($"scale out workers {_env.ScalingType}. {_ns}/{_env.Name} ({processCount} pods)");

            // confirm kubernetes master can connect with cluster api.
            Console.WriteLine($"checking cluster Endpoint health.");
            var healthy = await _operations.TryConnectClusterEndpointAsync(_env.ClusterEndpointHealthRetry, TimeSpan.FromSeconds(_env.ClusterEndpointHealthInterval), cancellationToken);

            if (!healthy)
            {
                Console.WriteLine($"cluster endpoint is unhealthy, quiting scale out.");
                _failSignal.TrySetException(new KubernetesException("Could not connect to Kubernetes Cluster Endpoint. Make sure pod can communicate with cluster api."));
            }
            else
            {
                // create worker resource
                switch (_env.ScalingType)
                {
                case ScalingType.Deployment:
                    await ScaleoutDeploymentAsync(processCount, options.WorkerConnectToHost, options.WorkerConnectToPort, cancellationToken);

                    break;

                case ScalingType.Job:
                    await ScaleoutJobAsync(processCount, options.WorkerConnectToHost, options.WorkerConnectToPort, cancellationToken);

                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(ScalingType));
                }
            }
        }
예제 #2
0
        async Task Core(IServiceProvider provider, DFrameOptions options, CancellationToken cancellationToken)
        {
            // create shim of ConsoleApp
            try
            {
                var logger  = provider.GetService(typeof(ILogger <DFrameWorkerApp>));
                var logger2 = provider.GetService(typeof(ILogger <ConsoleAppFramework.ConsoleAppEngine>));
                var app     = new DFrameWorkerApp((ILogger <DFrameWorkerApp>)logger, provider, options);
                app.Context = new ConsoleAppFramework.ConsoleAppContext(new string[0], DateTime.UtcNow, cancellationToken, (ILogger <ConsoleAppFramework.ConsoleAppEngine>)logger2);

                await app.Main();
            }
            catch (Exception ex)
            {
                failSignal.TrySetException(ex);
            }
        }
예제 #3
0
 async void WriteAll(ProcessAsyncEnumerable e)
 {
     try
     {
         await foreach (var item in e.WithCancellation(cts.Token))
         {
             Console.WriteLine(item);
         }
     }
     catch (Exception ex)
     {
         if (ex is OperationCanceledException)
         {
             return;
         }
         failSignal.TrySetException(ex);
     }
 }