in src/Microsoft.Azure.WebJobs.Host/Executors/JobHostContextFactory.cs [107:183]
public async Task<JobHostContext> Create(JobHost host, CancellationToken shutdownToken, CancellationToken cancellationToken)
{
shutdownToken.Register(() =>
{
// when a shutdown is triggered we want to stop the application, to ensure the host
// shuts down gracefully
_applicationLifetime.StopApplication();
});
using (CancellationTokenSource combinedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, shutdownToken))
{
CancellationToken combinedCancellationToken = combinedCancellationSource.Token;
await WriteSiteExtensionManifestAsync(combinedCancellationToken);
// TODO: FACAVAL: Chat with Brettsam, this should probably be moved out of here.
_loggerFactory.AddProvider(new FunctionOutputLoggerProvider());
IFunctionIndex functions = await _functionIndexProvider.GetAsync(combinedCancellationToken);
Action listenersCreatedCallback = () =>
{
// only trigger HostInitialized after all listeners are created (but before
// they are started).
host.OnHostInitialized();
};
IListenerFactory functionsListenerFactory = new HostListenerFactory(functions.ReadAll(), _loggerFactory, _monitorManager, _targetScalerManager, _listenerDecorators, listenersCreatedCallback, _drainModeManager);
string hostId = await _hostIdProvider.GetHostIdAsync(cancellationToken);
bool dashboardLoggingEnabled = _dashboardLoggingSetup.Setup(functions, functionsListenerFactory, out IFunctionExecutor hostCallExecutor,
out IListener listener, out HostOutputMessage hostOutputMessage, hostId, shutdownToken);
if (dashboardLoggingEnabled)
{
// Publish this to Azure logging account so that a web dashboard can see it.
await LogHostStartedAsync(functions, hostOutputMessage, _hostInstanceLogger, combinedCancellationToken);
}
if (_functionExecutor is FunctionExecutor executor)
{
executor.HostOutputMessage = hostOutputMessage;
}
IEnumerable<FunctionDescriptor> descriptors = functions.ReadAllDescriptors();
int descriptorsCount = descriptors.Count();
ILogger startupLogger = _loggerFactory?.CreateLogger(LogCategories.Startup);
if (_jobHostOptions.Value.UsingDevelopmentSettings)
{
startupLogger?.LogDebug("Development settings applied");
}
if (descriptorsCount == 0)
{
startupLogger?.LogWarning($"No job functions found. Try making your job classes and methods public. {Resource.ExtensionInitializationMessage}");
}
else
{
StringBuilder functionsTrace = new StringBuilder();
functionsTrace.AppendLine("Found the following functions:");
foreach (FunctionDescriptor descriptor in descriptors)
{
functionsTrace.AppendLine(descriptor.FullName);
}
string msg = functionsTrace.ToString();
startupLogger?.LogInformation(msg);
}
return new JobHostContext(
functions,
hostCallExecutor,
listener,
_eventCollector,
_loggerFactory);
}
}