/// <summary>
        /// Middleware invoke process
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Path.Value.ToLower().Contains("/health"))
            {
                LightHealthResult healthResult = new LightHealthResult();
                healthResult.Status = LightHealth.HealthCheck.Healthy.ToString();
                LightHealth.CheckHealth(healthResult);
                foreach (var key in healthResult.CartridgesStatus)
                {
                    if (key.Status == LightHealth.HealthCheck.Unhealthy.ToString())
                    {
                        healthResult.Status         = LightHealth.HealthCheck.Unhealthy.ToString();
                        context.Response.StatusCode = 503; // ServiceUnavailable
                    }
                    else
                    {
                        context.Response.StatusCode = 200; // Success
                    }
                }
                var jsonFile = JsonConvert.SerializeObject(healthResult);
                await context.Response.WriteAsync(jsonFile);

                return;
            }

            await _next.Invoke(context);
        }
示例#2
0
 /// <summary>
 /// Check active services, calls the HealthCheck for each active cartridges and return the Dictionary for response
 /// </summary>
 /// <returns></returns>
 private static void CheckActiveServices(LightHealthResult lightHealthResult)
 {
     foreach (var keys in WorkBench._singletonCache.Keys)
     {
         LightHealthCartridgeResult cartridgeResult = new LightHealthCartridgeResult();
         cartridgeResult.Name   = keys.ToString();
         cartridgeResult.Status = CheckUp(keys, WorkBench._singletonCache[keys].ToString()).ToString();
         lightHealthResult.CartridgesStatus.Add(cartridgeResult);
     }
 }
示例#3
0
 /// <summary>
 /// Start getting active cartridges at workbench
 /// </summary>
 /// <returns></returns>
 public static void CheckHealth(LightHealthResult lightHealthResult)
 {
     CheckActiveServices(lightHealthResult);
 }