Ejemplo n.º 1
0
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     try
     {
         _logger.LogInformation("Starting grpc server...");
         await _grpcServer.StartAsync();
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, $"Error initializing grpc server");
     }
 }
Ejemplo n.º 2
0
        private async Task InitializeWorkersAsync()
        {
            var serverImpl = new FunctionRpcService(EventManager, _logger);
            var server     = new GrpcServer(serverImpl, ScriptOptions.MaxMessageLengthBytes);

            using (_metricsLogger.LatencyEvent(MetricEventNames.HostStartupGrpcServerLatency))
            {
                await server.StartAsync();
            }

            var processFactory = new DefaultWorkerProcessFactory();

            try
            {
                _processRegistry = ProcessRegistryFactory.Create();
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "Unable to create process registry");
            }

            CreateChannel channelFactory = (languageWorkerConfig, registrations, attemptCount) =>
            {
                return(new LanguageWorkerChannel(
                           ScriptOptions,
                           EventManager,
                           processFactory,
                           _processRegistry,
                           registrations,
                           languageWorkerConfig,
                           server.Uri,
                           _loggerFactory, // TODO: DI (FACAVAL) Pass appropriate logger. Channel facory should likely be a service.
                           _metricsLogger,
                           attemptCount));
            };

            _functionDispatcher = new FunctionDispatcher(EventManager, server, channelFactory, _workerConfigs, _language);

            _eventSubscriptions.Add(EventManager.OfType <WorkerProcessErrorEvent>()
                                    .Subscribe(evt =>
            {
                HandleHostError(evt.Exception);
            }));
        }