feat: Task status statistics

Signed-off-by: jagger <cossjie@foxmail.com>

Former-commit-id: 2c01ea8c254c0a4a2bb1f80ed77f5bfcfe5726d4
This commit is contained in:
jagger 2024-04-19 17:09:54 +08:00
parent 304f0c7dae
commit 4fe78dee51
1 changed files with 11 additions and 3 deletions

View File

@ -24,14 +24,22 @@ func NewCountTaskStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
}
type taskStatus struct {
Quantity string `json:"quantity"`
Status string `json:"status"`
Succeeded int `json:"Succeeded"`
Failed int `json:"Failed"`
Running int `json:"Running"`
Pause int `json:"Pause"`
}
func (l *CountTaskStatusLogic) CountTaskStatus() (resp *types.ListResult, err error) {
resp = &types.ListResult{}
var taskStatusList []*taskStatus
err = l.svcCtx.DbEngin.Raw("select count(*) quantity, status from task group by status").Scan(&taskStatusList).Error
sqlStr := `SELECT
COUNT(CASE WHEN status = 'Succeeded' THEN 1 END) AS Succeeded,
COUNT(CASE WHEN status = 'Failed' THEN 1 END) AS Failed,
COUNT(CASE WHEN status = 'Running' THEN 1 END) AS Running,
COUNT(CASE WHEN status = 'Pause' THEN 1 END) AS Pause
FROM task;`
err = l.svcCtx.DbEngin.Raw(sqlStr).Scan(&taskStatusList).Error
if err != nil {
logx.Errorf("CountTaskStatus() => sql execution error: %v", err)
return nil, errors.Errorf("Description Failed to collect statistics on the status of a task. Please try again later")