in src/WebJobs.Script.WebHost/Controllers/HostController.cs [125:186]
public async Task<IActionResult> GetWorkerProcesses([FromServices] IScriptHostManager scriptHostManager)
{
if (!Utility.TryGetHostService(scriptHostManager, out IWebHostRpcWorkerChannelManager webHostLanguageWorkerChannelManager))
{
return StatusCode(StatusCodes.Status503ServiceUnavailable);
}
var hostProcess = Process.GetCurrentProcess();
List<FunctionProcesses.FunctionProcessInfo> processes = new()
{
new FunctionProcesses.FunctionProcessInfo()
{
ProcessId = hostProcess.Id,
DebugEngine = RpcWorkerConstants.DotNetCoreDebugEngine,
IsEligibleForOpenInBrowser = false,
ProcessName = hostProcess.ProcessName
}
};
string workerRuntime = _environment.GetFunctionsWorkerRuntime();
List<IRpcWorkerChannel> channels = null;
if (Utility.TryGetHostService(scriptHostManager, out IJobHostRpcWorkerChannelManager jobHostLanguageWorkerChannelManager))
{
channels = jobHostLanguageWorkerChannelManager.GetChannels(workerRuntime).ToList();
}
var webhostChannelDictionary = webHostLanguageWorkerChannelManager.GetChannels(workerRuntime);
List<Task<IRpcWorkerChannel>> webHostchannelTasks = new List<Task<IRpcWorkerChannel>>();
if (webhostChannelDictionary is not null)
{
foreach (var pair in webhostChannelDictionary)
{
var workerChannel = pair.Value.Task;
webHostchannelTasks.Add(workerChannel);
}
}
var webHostchannels = await Task.WhenAll(webHostchannelTasks);
channels = channels ?? new List<IRpcWorkerChannel>();
channels.AddRange(webHostchannels);
foreach (var channel in channels)
{
var processInfo = new FunctionProcesses.FunctionProcessInfo()
{
ProcessId = channel.WorkerProcess.Process.Id,
ProcessName = channel.WorkerProcess.Process.ProcessName,
DebugEngine = Utility.GetDebugEngineInfo(channel.WorkerConfig, workerRuntime),
IsEligibleForOpenInBrowser = false
};
processes.Add(processInfo);
}
var functionProcesses = new FunctionProcesses()
{
Processes = processes
};
return Ok(functionProcesses);
}