public override bool TrySetupRequestToProperResource(out RequestWebApiEventArgs args) { var tenantId = CountersName; if (string.IsNullOrWhiteSpace(tenantId)) { throw new HttpException(503, "Could not find a counter with no name"); } Task<CounterStorage> resourceStoreTask; bool hasDb; try { hasDb = landlord.TryGetOrCreateResourceStore(tenantId, out resourceStoreTask); } catch (Exception e) { var cle = e as ConcurrentLoadTimeoutException; string msg; if (cle != null) { msg = string.Format("The counter {0} is currently being loaded, but there are too many requests waiting for database load. Please try again later, database loading continues.", tenantId); } else { msg = "Could not open database named: " + tenantId + " " + e.Message; } Logger.WarnException(msg, e); throw new HttpException(503, msg, e); } if (hasDb) { try { if (resourceStoreTask.Wait(TimeSpan.FromSeconds(30)) == false) { var msg = "The counter " + tenantId + " is currently being loaded, but after 30 seconds, this request has been aborted. Please try again later, file system loading continues."; Logger.Warn(msg); throw new HttpException(503, msg); } args = new RequestWebApiEventArgs { Controller = this, IgnoreRequest = false, TenantId = tenantId, Counters = resourceStoreTask.Result }; if (args.IgnoreRequest) return false; } catch (Exception e) { var msg = "Could open counters named: " + tenantId; Logger.WarnException(msg, e); throw new HttpException(503, msg, e); } landlord.LastRecentlyUsed.AddOrUpdate(tenantId, SystemTime.UtcNow, (s, time) => SystemTime.UtcNow); } else { var msg = "Could not find a counter named: " + tenantId; Logger.Warn(msg); throw new HttpException(503, msg); } return true; }
private void RequestManagerOnBeforeRequest(object sender, RequestWebApiEventArgs requestWebApiEventArgs) { if (shouldRecordRequests) requestLog.Add(requestWebApiEventArgs.Controller.InnerRequest); }