public async Task InitializeAsync(IEnumerable <FunctionMetadata> functions) { if (functions == null || !functions.Any()) { // do not initialize function dispachter if there are no functions return; } State = FunctionInvocationDispatcherState.Initializing; await InitializeJobhostLanguageWorkerChannelAsync(0); }
public async Task InitializeAsync(IEnumerable <FunctionMetadata> functions, CancellationToken cancellationToken = default) { if (functions == null || !functions.Any()) { // do not initialize function dispachter if there are no functions return; } State = FunctionInvocationDispatcherState.Initializing; await InitializeHttpWorkerChannelAsync(0, cancellationToken); }
public async Task FunctionDispatcher_DelaysInvoke_WhenNotReady(FunctionInvocationDispatcherState state, bool delaysExecution) { _mockFunctionInvocationDispatcher.Setup(a => a.State).Returns(state); var timeoutTask = Task.Delay(TimeSpan.FromSeconds(2)); var invokeCoreTask = _testFunctionInvoker.InvokeCore(new object[] { }, null); var result = await Task.WhenAny(invokeCoreTask, timeoutTask); if (delaysExecution) { Assert.Equal(timeoutTask, result); } else { Assert.Equal(invokeCoreTask, result); } }
internal Task InitializeJobhostLanguageWorkerChannelAsync(int attemptCount) { // TODO: Add process managment for http invoker _httpWorkerChannel = _httpWorkerChannelFactory.Create(_scriptOptions.RootScriptPath, _metricsLogger, attemptCount); _httpWorkerChannel.StartWorkerProcessAsync().ContinueWith(workerInitTask => { if (workerInitTask.IsCompleted) { _logger.LogDebug("Adding http worker channel. workerId:{id}", _httpWorkerChannel.Id); State = FunctionInvocationDispatcherState.Initialized; } else { _logger.LogWarning("Failed to start http worker process. workerId:{id}", _httpWorkerChannel.Id); } }); return(Task.CompletedTask); }
internal Task InitializeJobhostLanguageWorkerChannelAsync(int attemptCount) { var rpcWorkerChannel = _rpcWorkerChannelFactory.Create(_scriptOptions.RootScriptPath, _workerRuntime, _metricsLogger, attemptCount); rpcWorkerChannel.SetupFunctionInvocationBuffers(_functions); _jobHostLanguageWorkerChannelManager.AddChannel(rpcWorkerChannel); rpcWorkerChannel.StartWorkerProcessAsync().ContinueWith(workerInitTask => { if (workerInitTask.IsCompleted) { _logger.LogDebug("Adding jobhost language worker channel for runtime: {language}. workerId:{id}", _workerRuntime, rpcWorkerChannel.Id); rpcWorkerChannel.SendFunctionLoadRequests(_managedDependencyOptions.Value); State = FunctionInvocationDispatcherState.Initialized; } else { _logger.LogWarning("Failed to start language worker process for runtime: {language}. workerId:{id}", _workerRuntime, rpcWorkerChannel.Id); } }); return(Task.CompletedTask); }
public async Task InitializeAsync(IEnumerable <FunctionMetadata> functions, CancellationToken cancellationToken = default) { if (_environment.IsPlaceholderModeEnabled()) { return; } _workerRuntime = _workerRuntime ?? Utility.GetWorkerRuntime(functions); _functions = functions; if (string.IsNullOrEmpty(_workerRuntime) || _workerRuntime.Equals(RpcWorkerConstants.DotNetLanguageWorkerName, StringComparison.InvariantCultureIgnoreCase)) { // Shutdown any placeholder channels for empty function apps or dotnet function apps. // This is needed as specilization does not kill standby placeholder channels if worker runtime is not set. // Debouce to ensure this does not effect cold start _shutdownStandbyWorkerChannels(); return; } if (functions == null || functions.Count() == 0) { // do not initialize function dispachter if there are no functions return; } if (Utility.IsSupportedRuntime(_workerRuntime, _workerConfigs)) { State = FunctionInvocationDispatcherState.Initializing; Dictionary <string, TaskCompletionSource <IRpcWorkerChannel> > webhostLanguageWorkerChannels = _webHostLanguageWorkerChannelManager.GetChannels(_workerRuntime); if (webhostLanguageWorkerChannels != null) { foreach (string workerId in webhostLanguageWorkerChannels.Keys.ToList()) { if (webhostLanguageWorkerChannels.TryGetValue(workerId, out TaskCompletionSource <IRpcWorkerChannel> initializedLanguageWorkerChannelTask)) { _logger.LogDebug("Found initialized language worker channel for runtime: {workerRuntime} workerId:{workerId}", _workerRuntime, workerId); try { IRpcWorkerChannel initializedLanguageWorkerChannel = await initializedLanguageWorkerChannelTask.Task; initializedLanguageWorkerChannel.SetupFunctionInvocationBuffers(_functions); initializedLanguageWorkerChannel.SendFunctionLoadRequests(_managedDependencyOptions.Value); } catch (Exception ex) { _logger.LogWarning(ex, "Removing errored webhost language worker channel for runtime: {workerRuntime} workerId:{workerId}", _workerRuntime, workerId); await _webHostLanguageWorkerChannelManager.ShutdownChannelIfExistsAsync(_workerRuntime, workerId); InitializeWebhostLanguageWorkerChannel(); } } } StartWorkerProcesses(webhostLanguageWorkerChannels.Count(), InitializeWebhostLanguageWorkerChannel); State = FunctionInvocationDispatcherState.Initialized; } else { await InitializeJobhostLanguageWorkerChannelAsync(0); StartWorkerProcesses(1, InitializeJobhostLanguageWorkerChannelAsync); } } }