fix: 解决进程状态一直加载中的问题 (#1983)

Refs #1968
This commit is contained in:
ssongliu 2023-08-17 14:46:09 +08:00 committed by GitHub
parent c3134e4c2a
commit e67d9055aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 21 deletions

View File

@ -196,7 +196,12 @@ func (b *BaseApi) GetProcess(c *gin.Context) {
// @Security ApiKeyAuth
// @Router /host/tool/supervisor/process/load [post]
func (b *BaseApi) LoadProcessStatus(c *gin.Context) {
helper.SuccessWithData(c, hostToolService.LoadProcessStatus())
datas, err := hostToolService.LoadProcessStatus()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, datas)
}
// @Tags Host tool

View File

@ -34,7 +34,7 @@ type IHostToolService interface {
GetToolLog(req request.HostToolLogReq) (string, error)
OperateSupervisorProcess(req request.SupervisorProcessConfig) error
GetSupervisorProcessConfig() ([]response.SupervisorProcessConfig, error)
LoadProcessStatus() []response.ProcessStatus
LoadProcessStatus() ([]response.ProcessStatus, error)
OperateSupervisorProcessFile(req request.SupervisorProcessFileReq) (string, error)
}
@ -377,11 +377,11 @@ func (h *HostToolService) OperateSupervisorProcess(req request.SupervisorProcess
return nil
}
func (h *HostToolService) LoadProcessStatus() []response.ProcessStatus {
func (h *HostToolService) LoadProcessStatus() ([]response.ProcessStatus, error) {
var datas []response.ProcessStatus
statuLines, err := cmd.Exec("supervisorctl status")
statuLines, err := cmd.Exec("supervisorct status")
if err != nil {
return datas
return datas, fmt.Errorf("exec `supervisorctl status` failed, err: %v", statuLines)
}
lines := strings.Split(string(statuLines), "\n")
for _, line := range lines {
@ -424,7 +424,7 @@ func (h *HostToolService) LoadProcessStatus() []response.ProcessStatus {
}(i)
}
wg.Wait()
return datas
return datas, nil
}
func (h *HostToolService) GetSupervisorProcessConfig() ([]response.SupervisorProcessConfig, error) {

View File

@ -1666,6 +1666,7 @@ const message = {
},
tool: {
supervisor: {
loadStatusErr: 'Failed to retrieve process status, please check the status of the supervisor service.',
notSupport: 'Supervisor is not detected, please refer to the official document for installation',
list: 'Daemon process',
config: 'Supervisor configuration',

View File

@ -1580,6 +1580,7 @@ const message = {
},
tool: {
supervisor: {
loadStatusErr: '獲取進程狀態失敗請檢查 supervisor 服務狀態',
notSupport: '未檢測到 Supervisor請參考官方文檔進行安裝',
list: '守護進程',
config: 'Supervisor 配置',

View File

@ -1582,6 +1582,7 @@ const message = {
},
tool: {
supervisor: {
loadStatusErr: '获取进程状态失败请检查 supervisor 服务状态',
notSupport: '未检测到 Supervisor请参考官方文档进行安装',
list: '守护进程',
config: 'Supervisor 配置',

View File

@ -221,11 +221,9 @@ const search = async () => {
};
const loadStatus = async () => {
const res = await LoadProcessStatus();
await LoadProcessStatus()
.then((res) => {
let stats = res.data || [];
if (stats.length === 0) {
return;
}
for (const process of data.value) {
process.status = [];
for (const item of stats) {
@ -237,6 +235,13 @@ const loadStatus = async () => {
process.hasLoad = true;
}
}
})
.catch(() => {
for (const process of data.value) {
process.status = [{ name: '-', status: 'FATAL', msg: i18n.global.t('tool.supervisor.loadStatusErr') }];
process.hasLoad = true;
}
});
};
const mobile = computed(() => {