public async Task <MiscGrpcResponse> GetSiteStatAsync(MiscGrpcRequest request, CallContext context = default) { var response = new MiscGrpcResponse(); try { if (request.Site == LaobianSite.Jarvis) { response.SiteStat = await _jarvisHttpClient.GetSiteStatAsync(); } else if (request.Site == LaobianSite.Blog) { response.SiteStat = await _blogHttpClient.GetSiteStatAsync(); } else if (request.Site == LaobianSite.Api) { response.SiteStat = SiteStatHelper.Get(); } else { response.IsOk = false; response.Message = $"Getting site {request.Site} stat not supported."; } } catch (Exception ex) { response.IsOk = false; response.Message = ex.Message; _logger.LogError(ex, $"{nameof(GetSiteStatAsync)} failed."); } return(response); }
public async Task <MiscGrpcResponse> ShutdownSiteAsync(MiscGrpcRequest request, CallContext context = default) { var response = new MiscGrpcResponse(); try { if (request.Site == LaobianSite.Api) { _appLifetime.StopApplication(); } else if (request.Site == LaobianSite.Blog) { await _blogHttpClient.ShutdownAsync(); } else if (request.Site == LaobianSite.Jarvis) { await _jarvisHttpClient.ShutdownAsync(); } else { response.IsOk = false; response.Message = $"Shutdown site {request.Site} not supported."; } } catch (Exception ex) { response.IsOk = false; response.Message = ex.Message; _logger.LogError(ex, $"{nameof(ShutdownSiteAsync)} failed."); } return(response); }
public async Task <ApiResponse <object> > ShutdownAsync() { var apiResponse = new ApiResponse <object>(); try { var request = new MiscGrpcRequest { Site = LaobianSite.Blog }; await _miscGrpcService.ShutdownSiteAsync(request); request.Site = LaobianSite.Jarvis; await _miscGrpcService.ShutdownSiteAsync(request); request.Site = LaobianSite.Api; await _miscGrpcService.ShutdownSiteAsync(request); _appLifetime.StopApplication(); } catch (Exception ex) { _logger.LogError(ex, "Shutdown site failed."); } return(apiResponse); }
public async Task <MiscGrpcResponse> PersistentGitFileAsync(MiscGrpcRequest request, CallContext context = default) { var response = new MiscGrpcResponse(); try { await _gitFileService.PushAsync(request.Message); } catch (Exception ex) { response.IsOk = false; response.Message = ex.Message; _logger.LogError(ex, $"{nameof(PersistentGitFileAsync)} failed."); } return(response); }
public async Task <MiscGrpcResponse> GetDbStatAsync(MiscGrpcRequest request, CallContext context = default) { var response = new MiscGrpcResponse(); try { response.DbStats = await _gitFileService.GetGitFileStatsAsync(); } catch (Exception ex) { response.IsOk = false; response.Message = ex.Message; _logger.LogError(ex, $"{nameof(GetDbStatAsync)} failed."); } return(response); }