pcm-coordinator/internal/logic/monitoring/tasknumlogic.go

34 lines
1.1 KiB
Go

package monitoring
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type TaskNumLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewTaskNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskNumLogic {
return &TaskNumLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *TaskNumLogic) TaskNum(req *types.TaskNumReq) (resp *types.TaskNumResp, err error) {
resp = &types.TaskNumResp{}
l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ? and status = 'running'", req.ClusterId).Scan(resp.Current)
l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = '' and DATE(start_time) = CURDATE()", req.ClusterId).Scan(resp.Today)
l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ?", req.ClusterId).Scan(resp.History)
l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ? and status = 'failed'", req.ClusterId).Scan(resp.Failed)
return resp, nil
}