public async Task Invoke(HttpContext httpContext) { if (_scriptHostManager.State != ScriptHostState.Offline) { bool hostReady = _scriptHostManager.CanInvoke(); if (!hostReady) { using (Logger.VerifyingHostAvailabilityScope(_logger, httpContext.TraceIdentifier)) { Logger.InitiatingHostAvailabilityCheck(_logger); 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 Task Invoke(HttpContext httpContext) { if (_scriptHostManager.State != ScriptHostState.Offline) { if (!_scriptHostManager.CanInvoke()) { // If we're not ready, take the slower/more expensive route and await being ready return(InvokeAwaitingHost(httpContext, _next, _logger, _scriptHostManager)); } // But if we are ready, bypass the awaiting cost and go right to the next middleware return(_next.Invoke(httpContext)); } else { return(httpContext.SetOfflineResponseAsync(_applicationHostOptions.CurrentValue.ScriptPath)); } }