public async Task <ILanguageWorkerChannel> InitializeChannelAsync(string language)
        {
            var metricsLogger = new Mock <IMetricsLogger>();
            ILanguageWorkerChannel workerChannel = _testLanguageWorkerChannelFactory.CreateLanguageWorkerChannel(_scriptRootPath, language, metricsLogger.Object, 0);

            if (_workerChannels.TryGetValue(language, out Dictionary <string, TaskCompletionSource <ILanguageWorkerChannel> > workerChannels))
            {
                workerChannels.Add(workerChannel.Id, new TaskCompletionSource <ILanguageWorkerChannel>());
            }
            else
            {
                _workerChannels.TryAdd(language, new Dictionary <string, TaskCompletionSource <ILanguageWorkerChannel> >());
                _workerChannels[language].Add(workerChannel.Id, new TaskCompletionSource <ILanguageWorkerChannel>());
            }

            await workerChannel.StartWorkerProcessAsync().ContinueWith(processStartTask =>
            {
                if (processStartTask.Status == TaskStatus.RanToCompletion)
                {
                    SetInitializedWorkerChannel(language, workerChannel);
                }
                else if (processStartTask.Status == TaskStatus.Faulted)
                {
                    SetExceptionOnInitializedWorkerChannel(language, workerChannel, processStartTask.Exception);
                }
            });

            return(workerChannel);
        }
        internal async Task <ILanguageWorkerChannel> InitializeLanguageWorkerChannel(string runtime, string scriptRootPath)
        {
            ILanguageWorkerChannel languageWorkerChannel = null;
            string workerId = Guid.NewGuid().ToString();

            _logger.LogDebug("Creating language worker channel for runtime:{runtime}", runtime);
            try
            {
                languageWorkerChannel = _languageWorkerChannelFactory.CreateLanguageWorkerChannel(scriptRootPath, runtime, null, 0);
                AddOrUpdateWorkerChannels(runtime, languageWorkerChannel);
                await languageWorkerChannel.StartWorkerProcessAsync().ContinueWith(processStartTask =>
                {
                    if (processStartTask.Status == TaskStatus.RanToCompletion)
                    {
                        _logger.LogDebug("Adding jobhost language worker channel for runtime: {language}. workerId:{id}", _workerRuntime, languageWorkerChannel.Id);
                        SetInitializedWorkerChannel(runtime, languageWorkerChannel);
                    }
                    else if (processStartTask.Status == TaskStatus.Faulted)
                    {
                        _logger.LogError("Failed to start language worker process for runtime: {language}. workerId:{id}", _workerRuntime, languageWorkerChannel.Id);
                        SetExceptionOnInitializedWorkerChannel(runtime, languageWorkerChannel, processStartTask.Exception);
                    }
                });
            }
            catch (Exception ex)
            {
                throw new HostInitializationException($"Failed to start Language Worker Channel for language :{runtime}", ex);
            }
            return(languageWorkerChannel);
        }
        private ILanguageWorkerChannel CreateTestChannel(string language)
        {
            var testChannel = _languageWorkerChannelFactory.CreateLanguageWorkerChannel(_scriptRootPath, language, null, 0, null);

            _languageWorkerChannelManager.AddOrUpdateWorkerChannels(language, testChannel);
            return(testChannel);
        }
        internal async Task InitializeJobhostLanguageWorkerChannelAsync(int attemptCount)
        {
            var languageWorkerChannel = _languageWorkerChannelFactory.CreateLanguageWorkerChannel(_scriptOptions.RootScriptPath, _workerRuntime, _metricsLogger, attemptCount, false, _managedDependencyOptions);

            languageWorkerChannel.SetupFunctionInvocationBuffers(_functions);
            _jobHostLanguageWorkerChannelManager.AddChannel(languageWorkerChannel);
            await languageWorkerChannel.StartWorkerProcessAsync();
        }
Esempio n. 5
0
        private ILanguageWorkerChannel CreateTestChannel(string language)
        {
            var testChannel = _languageWorkerChannelFactory.CreateLanguageWorkerChannel(_scriptRootPath, language, null, 0, false, null);
            // Generate event to mock language worker response
            RpcWebHostChannelReadyEvent javaReadyEvent = new RpcWebHostChannelReadyEvent(testChannel.Id, language, testChannel, "testVersion", _capabilities);

            _languageWorkerChannelManager.AddOrUpdateWorkerChannels(javaReadyEvent);
            return(testChannel);
        }
Esempio n. 6
0
        private async Task <ILanguageWorkerChannel> InitializeLanguageWorkerChannel(string runtime, string scriptRootPath)
        {
            ILanguageWorkerChannel languageWorkerChannel = null;
            string workerId = Guid.NewGuid().ToString();

            _logger.LogDebug("Creating language worker channel for runtime:{runtime}", runtime);
            try
            {
                languageWorkerChannel = _languageWorkerChannelFactory.CreateLanguageWorkerChannel(scriptRootPath, runtime, null, 0);
                await languageWorkerChannel.StartWorkerProcessAsync();

                AddOrUpdateWorkerChannels(runtime, languageWorkerChannel);
            }
            catch (Exception ex)
            {
                throw new HostInitializationException($"Failed to start Language Worker Channel for language :{runtime}", ex);
            }
            return(languageWorkerChannel);
        }
Esempio n. 7
0
        internal Task InitializeJobhostLanguageWorkerChannelAsync(int attemptCount)
        {
            var languageWorkerChannel = _languageWorkerChannelFactory.CreateLanguageWorkerChannel(_scriptOptions.RootScriptPath, _workerRuntime, _metricsLogger, attemptCount, _managedDependencyOptions);

            languageWorkerChannel.SetupFunctionInvocationBuffers(_functions);
            _jobHostLanguageWorkerChannelManager.AddChannel(languageWorkerChannel);
            languageWorkerChannel.StartWorkerProcessAsync().ContinueWith(workerInitTask =>
            {
                if (workerInitTask.IsCompleted)
                {
                    _logger.LogDebug("Adding jobhost language worker channel for runtime: {language}. workerId:{id}", _workerRuntime, languageWorkerChannel.Id);
                    languageWorkerChannel.SendFunctionLoadRequests();
                    State = FunctionDispatcherState.Initialized;
                }
                else
                {
                    _logger.LogWarning("Failed to start language worker process for runtime: {language}. workerId:{id}", _workerRuntime, languageWorkerChannel.Id);
                }
            });
            return(Task.CompletedTask);
        }
        private async Task <ILanguageWorkerChannel> InitializeLanguageWorkerChannel(string runtime, string scriptRootPath)
        {
            ILanguageWorkerChannel languageWorkerChannel = null;
            string workerId = Guid.NewGuid().ToString();

            _logger.LogDebug("Creating language worker channel for runtime:{runtime}", runtime);
            try
            {
                languageWorkerChannel = _languageWorkerChannelFactory.CreateLanguageWorkerChannel(scriptRootPath, runtime, null, 0, true);
                await languageWorkerChannel.StartWorkerProcessAsync();

                IObservable <RpcWebHostChannelReadyEvent> rpcChannelReadyEvent = _eventManager.OfType <RpcWebHostChannelReadyEvent>()
                                                                                 .Where(msg => msg.Language == runtime).Timeout(workerInitTimeout);
                // Wait for response from language worker process
                RpcWebHostChannelReadyEvent readyEvent = await rpcChannelReadyEvent.FirstAsync();

                AddOrUpdateWorkerChannels(readyEvent);
            }
            catch (Exception ex)
            {
                throw new HostInitializationException($"Failed to start Language Worker Channel for language :{runtime}", ex);
            }
            return(languageWorkerChannel);
        }