Browse Source

update

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
44e6ef953a
2 changed files with 62 additions and 9 deletions
  1. +21
    -9
      models/cloudbrain_static.go
  2. +41
    -0
      routers/api/v1/repo/cloudbrain_dashboard.go

+ 21
- 9
models/cloudbrain_static.go View File

@@ -77,15 +77,6 @@ func GetJobFailedPeriodCount(beginTime time.Time, endTime time.Time) (int64, err
return x.SQL(countSql).Count()
}

// func GetWaitingCount(beginTime time.Time, endTime time.Time) (int64, error) {
// countSql := "SELECT distinct count(*) FROM " +
// "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
// " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
// " and status ='" + string(JobWaiting) + "'"

// return x.SQL(countSql).Count()
// }

func GetDebugOnePeriodCount(beginTime time.Time, endTime time.Time) (int64, error) {
countSql := "SELECT count(*) FROM " +
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
@@ -302,3 +293,24 @@ func CreateCloudbrainStatistic(cloudbrainStat *CloudbrainStatistic) (err error)
}
return nil
}

func GetJobWaitingCount() (int64, error) {
countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobWaiting) + "'"
return x.SQL(countSql).Count()
}
func GetJobStoppedCount() (int64, error) {
countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobStopped) + "'"
return x.SQL(countSql).Count()
}
func GetJobSucceededCount() (int64, error) {
countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobSucceeded) + "'"
return x.SQL(countSql).Count()
}
func GetJobFailedCount() (int64, error) {
countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobFailed) + "'"
return x.SQL(countSql).Count()
}
func GetJobRunningCount() (int64, error) {
countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobRunning) + "'"
return x.SQL(countSql).Count()
}

+ 41
- 0
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -40,6 +40,14 @@ type CloudbrainsOverviewData struct {
CreatorPeriodCount int64 `json:"creatorPeriodCount"`
CreatorCount int64 `json:"creatorCount"`
}

type CloudbrainsStatusAnalysis struct {
JobWaitingCount int64 `json:"jobWaitingCount"`
JobRunningCount int64 `json:"jobRunningCount"`
JobStoppedCount int64 `json:"jobStoppedCount"`
JobSucceededCount int64 `json:"jobSucceededCount"`
JobFailedCount int64 `json:"jobFailedCount"`
}
type TimeCloudbrainsNum struct {
TimeCloudbrainNum []DateCloudbrainNum `json:"dateCloudbrainNum"`
}
@@ -370,7 +378,40 @@ func GetAllCloudbrainsPeriodDistribution(ctx *context.Context) {
}

func GetCloudbrainsStatusAnalysis(ctx *context.Context) {
jobWaitingCount, err := models.GetJobWaitingCount()
if err != nil {
log.Error("Can not query jobWaitingCount.", err)
return
}
jobRunningCount, err := models.GetJobRunningCount()
if err != nil {
log.Error("Can not query jobRunningCount.", err)
return
}
jobStoppedCount, err := models.GetJobStoppedCount()
if err != nil {
log.Error("Can not query jobStoppedCount.", err)
return
}
jobSucceededCount, err := models.GetJobSucceededCount()
if err != nil {
log.Error("Can not query jobSucceededCount.", err)
return
}
jobFailedCount, err := models.GetJobFailedCount()
if err != nil {
log.Error("Can not query jobFailedCount.", err)
return
}
cloudbrainsStatusAnalysis := CloudbrainsStatusAnalysis{
JobWaitingCount: jobWaitingCount,
JobRunningCount: jobRunningCount,
JobStoppedCount: jobStoppedCount,
JobSucceededCount: jobSucceededCount,
JobFailedCount: jobFailedCount,
}

ctx.JSON(http.StatusOK, cloudbrainsStatusAnalysis)
}

func getCloudbrainCount(beginTime time.Time, endTime time.Time) (int64, int64, int64, int64, int64, int64, int64, int64, int64, error) {


Loading…
Cancel
Save