private async Task DisposeAndRestartWorkerChannel(string runtime, string workerId)
        {
            bool isWebHostChannel = await _webHostLanguageWorkerChannelManager.ShutdownChannelIfExistsAsync(runtime, workerId);

            bool isJobHostChannel = false;

            // Dispose old worker
            if (isWebHostChannel)
            {
                _logger.LogDebug("Disposing WebHost channel for workerId: {channelId}, for runtime:{language}", workerId, runtime);
            }
            else
            {
                var channel = _jobHostLanguageWorkerChannelManager.GetChannels().Where(ch => ch.Id == workerId).FirstOrDefault();
                if (channel != null)
                {
                    _logger.LogDebug("Disposing JobHost channel for workerId: {channelId}, for runtime:{language}", workerId, runtime);
                    isJobHostChannel = true;
                    _jobHostLanguageWorkerChannelManager.DisposeAndRemoveChannel(channel);
                }
                else
                {
                    _logger.LogDebug("Did not find WebHost or JobHost channel to dispose for workerId: {channelId}, runtime:{language}", workerId, runtime);
                }
            }

            if (ShouldRestartWorkerChannel(runtime, isWebHostChannel, isJobHostChannel))
            {
                // Set state to "WorkerProcessRestarting" if there are no other workers to handle work
                if ((await GetInitializedWorkerChannelsAsync()).Count() == 0)
                {
                    State = FunctionInvocationDispatcherState.WorkerProcessRestarting;
                    _logger.LogDebug("No initialized worker channels for runtime '{runtime}'. Delaying future invocations", runtime);
                }
                // Restart worker channel
                _logger.LogDebug("Restarting worker channel for runtime:{runtime}", runtime);
                await RestartWorkerChannel(runtime, workerId);

                // State is set back to "Initialized" when worker channel is up again
            }
            else
            {
                _logger.LogDebug("Skipping worker channel restart for errored worker runtime:{runtime}, current runtime:{currentRuntime}, isWebHostChannel:{isWebHostChannel}, isJobHostChannel:{isJobHostChannel}",
                                 runtime, _workerRuntime, isWebHostChannel, isJobHostChannel);
            }
        }
Beispiel #2
0
        private async Task DisposeAndRestartWorkerChannel(string runtime, string workerId)
        {
            bool isWebHostChannel = await _webHostLanguageWorkerChannelManager.ShutdownChannelIfExistsAsync(runtime, workerId);

            bool isJobHostChannel = false;

            if (!isWebHostChannel)
            {
                _logger.LogDebug("Disposing channel for workerId: {channelId}, for runtime:{language}", workerId, runtime);
                var channel = _jobHostLanguageWorkerChannelManager.GetChannels().Where(ch => ch.Id == workerId).FirstOrDefault();
                if (channel != null)
                {
                    isJobHostChannel = true;
                    _jobHostLanguageWorkerChannelManager.DisposeAndRemoveChannel(channel);
                }
            }
            if (ShouldRestartWorkerChannel(runtime, isWebHostChannel, isJobHostChannel))
            {
                _logger.LogDebug("Restarting worker channel for runtime:{runtime}", runtime);
                await RestartWorkerChannel(runtime, workerId);
            }
        }
Beispiel #3
0
        private async Task DisposeAndRestartWorkerChannel(string runtime, string workerId)
        {
            bool isWebHostChannel = await _webHostLanguageWorkerChannelManager.ShutdownChannelIfExistsAsync(runtime, workerId);

            bool isJobHostChannel = false;

            // Dispose old worker
            if (isWebHostChannel)
            {
                _logger.LogDebug("Disposing WebHost channel for workerId: {channelId}, for runtime:{language}", workerId, runtime);
            }
            else
            {
                var channel = _jobHostLanguageWorkerChannelManager.GetChannels().Where(ch => ch.Id == workerId).FirstOrDefault();
                if (channel != null)
                {
                    _logger.LogDebug("Disposing JobHost channel for workerId: {channelId}, for runtime:{language}", workerId, runtime);
                    isJobHostChannel = true;
                    _jobHostLanguageWorkerChannelManager.DisposeAndRemoveChannel(channel);
                }
                else
                {
                    _logger.LogDebug("Did not find WebHost or JobHost channel to dispose for workerId: {channelId}, runtime:{language}", workerId, runtime);
                }
            }

            if (ShouldRestartWorkerChannel(runtime, isWebHostChannel, isJobHostChannel))
            {
                _logger.LogDebug("Restarting worker channel for runtime:{runtime}", runtime);
                await RestartWorkerChannel(runtime, workerId);
            }
            else
            {
                _logger.LogDebug("Skipping worker channel restart for errored worker runtime:{runtime}, current runtime:{currentRuntime}, isWebHostChannel:{isWebHostChannel}, isJobHostChannel:{isJobHostChannel}",
                                 runtime, _workerRuntime, isWebHostChannel, isJobHostChannel);
            }
        }