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); }
public Task <ILanguageWorkerChannel> InitializeChannelAsync(string language) { ILanguageWorkerChannel workerChannel = CreateLanguageWorkerChannel(Guid.NewGuid().ToString(), _scriptRootPath, language, null, 0, true); workerChannel.StartWorkerProcessAsync(); return(Task.FromResult(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 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); }
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 = CreateLanguageWorkerChannel(workerId, 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(); } catch (Exception ex) { throw new HostInitializationException($"Failed to start Language Worker Channel for language :{runtime}", ex); } return(languageWorkerChannel); }