public async Task Invoke(HttpContext httpContext, IScriptHostManager scriptHostManager) { if (scriptHostManager.State != ScriptHostState.Offline) { using (Logger.VerifyingHostAvailabilityScope(_logger, httpContext.TraceIdentifier)) { Logger.InitiatingHostAvailabilityCheck(_logger); bool hostReady = await scriptHostManager.DelayUntilHostReady(); if (!hostReady) { Logger.HostUnavailableAfterCheck(_logger); httpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; await httpContext.Response.WriteAsync("Function host is not running."); return; } Logger.HostAvailabilityCheckSucceeded(_logger); await _next.Invoke(httpContext); } } else { await httpContext.SetOfflineResponseAsync(_applicationHostOptions.CurrentValue.ScriptPath); } }
public async Task SpecializeHostCoreAsync() { // Go async immediately to ensure that any async context from // the PlaceholderSpecializationMiddleware is properly suppressed. await Task.Yield(); _logger.LogInformation(Resources.HostSpecializationTrace); // After specialization, we need to ensure that custom timezone // settings configured by the user (WEBSITE_TIME_ZONE) are honored. // DateTime caches timezone information, so we need to clear the cache. TimeZoneInfo.ClearCachedData(); // Trigger a configuration reload to pick up all current settings _configuration?.Reload(); _hostNameProvider.Reset(); await _languageWorkerChannelManager.SpecializeAsync(); NotifyChange(); await _scriptHostManager.RestartHostAsync(); await _scriptHostManager.DelayUntilHostReady(); }
public async Task Invoke(HttpContext httpContext, IScriptHostManager scriptHostManager) { if (scriptHostManager.State != ScriptHostState.Offline) { using (Logger.VerifyingHostAvailabilityScope(_logger, httpContext.TraceIdentifier)) { Logger.InitiatingHostAvailabilityCheck(_logger); bool hostReady = await scriptHostManager.DelayUntilHostReady(); if (!hostReady) { Logger.HostUnavailableAfterCheck(_logger); httpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; await httpContext.Response.WriteAsync("Function host is not running."); return; } Logger.HostAvailabilityCheckSucceeded(_logger); await _next.Invoke(httpContext); } } else { // host is offline so return the app_offline.htm file content var offlineFilePath = Path.Combine(_applicationHostOptions.CurrentValue.ScriptPath, ScriptConstants.AppOfflineFileName); httpContext.Response.ContentType = "text/html"; httpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; await httpContext.Response.SendFileAsync(offlineFilePath); } }
public async Task SpecializeHostCoreAsync() { NotifyChange(); await _scriptHostManager.RestartHostAsync(); await _scriptHostManager.DelayUntilHostReady(); }
public async Task WarmUp(HttpRequest request) { if (request.Query.TryGetValue("restart", out StringValues value) && string.Compare("1", value) == 0) { await _hostManager.RestartHostAsync(CancellationToken.None); // This call is here for sanity, but we should be fully initialized. await _hostManager.DelayUntilHostReady(); } }
public override async Task OnActionExecutionAsync(ActionExecutingContext actionContext, ActionExecutionDelegate next) { // If the host is not ready, we'll wait a bit for it to initialize. // This might happen if http requests come in while the host is starting // up for the first time, or if it is restarting. bool hostReady = await _hostManager.DelayUntilHostReady(TimeoutSeconds, PollingIntervalMilliseconds); if (!hostReady) { throw new HttpException(HttpStatusCode.ServiceUnavailable, "Function host is not running."); } await next(); }
public async Task <IActionResult> Get() { string hostKeyScope = GetHostKeyScopeForRequest(); if (string.Equals(hostKeyScope, HostKeyScopes.SystemKeys, StringComparison.OrdinalIgnoreCase) && _hostManager.State != ScriptHostState.Offline) { // Extensions that are webhook providers create their default system keys // as part of host initialization (when those keys aren't already present). // So we must delay key retrieval until host initialization is complete. await _hostManager.DelayUntilHostReady(); } Dictionary <string, string> keys = await GetHostSecretsByScope(hostKeyScope); return(GetKeysResult(keys)); }
public async Task SpecializeHostCoreAsync() { _logger.LogInformation(Resources.HostSpecializationTrace); // After specialization, we need to ensure that custom timezone // settings configured by the user (WEBSITE_TIME_ZONE) are honored. // DateTime caches timezone information, so we need to clear the cache. TimeZoneInfo.ClearCachedData(); // Trigger a configuration reload to pick up all current settings _configuration?.Reload(); NotifyChange(); await _scriptHostManager.RestartHostAsync(); await _scriptHostManager.DelayUntilHostReady(); }
public async Task SpecializeHostCoreAsync() { // Go async immediately to ensure that any async context from // the PlaceholderSpecializationMiddleware is properly suppressed. await Task.Yield(); _logger.LogInformation(Resources.HostSpecializationTrace); // After specialization, we need to ensure that custom timezone // settings configured by the user (WEBSITE_TIME_ZONE) are honored. // DateTime caches timezone information, so we need to clear the cache. TimeZoneInfo.ClearCachedData(); // Trigger a configuration reload to pick up all current settings _configuration?.Reload(); _hostNameProvider.Reset(); // Reset the shared load context to ensure we're reloading // user dependencies FunctionAssemblyLoadContext.ResetSharedContext(); // Signals change of JobHost options from placeholder mode // (ex: ScriptPath is updated) NotifyChange(); using (_metricsLogger.LatencyEvent(MetricEventNames.SpecializationLanguageWorkerChannelManagerSpecialize)) { await _rpcWorkerChannelManager.SpecializeAsync(); } using (_metricsLogger.LatencyEvent(MetricEventNames.SpecializationRestartHost)) { await _scriptHostManager.RestartHostAsync(); } using (_metricsLogger.LatencyEvent(MetricEventNames.SpecializationDelayUntilHostReady)) { await _scriptHostManager.DelayUntilHostReady(); } }
public override async Task OnActionExecutionAsync(ActionExecutingContext actionContext, ActionExecutionDelegate next) { if (_hostManager.State == ScriptHostState.Offline) { await actionContext.HttpContext.SetOfflineResponseAsync(_applicationHostOptions.CurrentValue.ScriptPath); } else { // If the host is not ready, we'll wait a bit for it to initialize. // This might happen if http requests come in while the host is starting // up for the first time, or if it is restarting. bool hostReady = await _hostManager.DelayUntilHostReady(TimeoutSeconds, PollingIntervalMilliseconds); if (!hostReady) { throw new HttpException(HttpStatusCode.ServiceUnavailable, "Function host is not running."); } await next(); } }
/// <summary> /// Slow path, for when the host isn't initialized and we need to wait. /// In this more rare case, we'll allocate the async/await state machine because it's necessary overhead. /// </summary> private static async Task InvokeAwaitingHost(HttpContext context, RequestDelegate next, ILogger <HostAvailabilityCheckMiddleware> logger, IScriptHostManager scriptHostManager) { using (Logger.VerifyingHostAvailabilityScope(logger, context.TraceIdentifier)) { Logger.InitiatingHostAvailabilityCheck(logger); bool hostReady = await scriptHostManager.DelayUntilHostReady(); if (!hostReady) { Logger.HostUnavailableAfterCheck(logger); context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; await context.Response.WriteAsync("Function host is not running."); return; } Logger.HostAvailabilityCheckSucceeded(logger); } await next.Invoke(context); }