Browse Source

update

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
3533627db0
2 changed files with 29 additions and 73 deletions
  1. +22
    -73
      models/cloudbrain_static.go
  2. +7
    -0
      routers/api/v1/repo/cloudbrain_dashboard.go

+ 22
- 73
models/cloudbrain_static.go View File

@@ -26,47 +26,6 @@ type TaskDetail struct {
RepoID int64 `json:"RepoID"`
}

// func GetJobWaitingPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) {
// countSql := "SELECT 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 GetJobRunningPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) {
// countSql := "SELECT count(*) FROM " +
// "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
// " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
// " and status ='" + string(JobRunning) + "'"

// return x.SQL(countSql).Count()
// }
// func GetJobStoppedPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) {
// countSql := "SELECT count(*) FROM " +
// "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
// " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
// " and status ='" + string(JobStopped) + "'"

// return x.SQL(countSql).Count()
// }
// func GetJobSucceededPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) {
// countSql := "SELECT count(*) FROM " +
// "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
// " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
// " and status ='" + string(JobSucceeded) + "'"

// return x.SQL(countSql).Count()
// }
// func GetJobFailedPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) {
// countSql := "SELECT count(*) FROM " +
// "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
// " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
// " and status ='" + string(JobFailed) + "'"

// 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) +
@@ -216,38 +175,28 @@ func GetAllCloudBrain() ([]*CloudbrainInfo, error) {
return cloudbrains, nil
}

// func GetCloudBrains(opts *CloudbrainsOptions) ([]*CloudbrainInfo, error) {
// sess := x.NewSession()
// defer sess.Close()
// var cond = builder.NewCond()
// if len(opts.JobStatus) > 0 {
// if opts.JobStatusNot {
// cond = cond.And(
// builder.NotIn("cloudbrain.status", opts.JobStatus),
// )
// } else {
// cond = cond.And(
// builder.In("cloudbrain.status", opts.JobStatus),
// )
// }
// }
// if opts.Page >= 0 && opts.PageSize > 0 {
// var start int
// if opts.Page == 0 {
// start = 0
// } else {
// start = (opts.Page - 1) * opts.PageSize
// }
// sess.Limit(opts.PageSize, start)
// }
// sess.OrderBy("cloudbrain.created_unix DESC")
// cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum)
// if err := sess.Table(&Cloudbrain{}).Where(cond).Unscoped().
// Find(&cloudbrains); err != nil {
// log.Info("find error.")
// }
// return cloudbrains, nil
// }
func GetRecordBeginTime() ([]*CloudbrainInfo, error) {
// sess := x.NewSession()
// defer sess.Close()

// cloudbrains := make([]*CloudbrainInfo, 0)
// if err := sess.Table(&Cloudbrain{}).
// Find(&cloudbrains); err != nil {
// return nil, fmt.Errorf("Find: %v", err)
// }

// return cloudbrains, nil

sess := x.NewSession()
defer sess.Close()
sess.OrderBy("cloudbrain.created_unix ASC limit 1")
cloudbrains := make([]*CloudbrainInfo, 0)
if err := sess.Table(&Cloudbrain{}).Unscoped().
Find(&cloudbrains); err != nil {
log.Info("find error.")
}
return cloudbrains, nil
}

func getCreatePeriodCount(dateBeginTime string, dateEndTime string, hourBeginTime string, hourEndTime string) (int64, error) {
countSql := "SELECT count(*) FROM " +


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

@@ -35,6 +35,12 @@ func GetAllCloudbrainsOverview(ctx *context.Context) {
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
return
}
recoreTime, err := models.GetRecordBeginTime()
if err != nil {
log.Error("Can not get record begin time", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
return
}
now := time.Now()
beginTime := now.AddDate(0, 0, 0)
beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location())
@@ -97,6 +103,7 @@ func GetAllCloudbrainsOverview(ctx *context.Context) {

ctx.JSON(http.StatusOK, map[string]interface{}{
"recordBeginTime": recordBeginTime,
"recoreTime": recoreTime[0].Cloudbrain.CreatedUnix,
"updateTime": now,
"cloudBrainNum": cloudBrainNum,
"cloudBrainOneDuration": cloudBrainOneDuration,


Loading…
Cancel
Save