package repo import ( "time" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/services/mailer" ) func CloudbrainStatisticAuto() { yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02") CloudbrainStatisticDaily(yesterday) } func CloudbrainStatisticDaily(date string) { log.Info("%s", date) log.Info("begin Cloudbrain Statistic") warnEmailMessage := "云脑任务统计信息入库失败,请尽快定位。" if err := models.DeleteCloudbrainStatisticDaily(date); err != nil { log.Error("DeleteCloudbrainStatisticDaily failed: %v", err.Error()) mailer.SendWarnNotifyMail(setting.Warn_Notify_Mails, warnEmailMessage) return } //0 to 23 for each hour, 25 for all 24 hours var WhichHour [25]int64 = [25]int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25} for _, whichHour := range WhichHour { log.Info("start statistic: %s", date) var beginTime, endTime time.Time beginTime, endTime = models.GetHourStatTime(date, whichHour) if whichHour == 25 { beginTime, endTime = models.GetDayStatTime(date) } numDubugOne, err := models.GetDebugOnePeriodCount(beginTime, endTime) if err != nil { log.Error("GetDebugOneCount failed(%s): %v", numDubugOne, err) } numBenchmarkOne, err := models.GetBenchmarkOnePeriodCount(beginTime, endTime) if err != nil { log.Error("GetBenchmarkOneCount failed(%s): %v", numBenchmarkOne, err) } numTrainOne, err := models.GetTrainOnePeriodCount(beginTime, endTime) if err != nil { log.Error("GetTrainOneCount failed(%s): %v", numTrainOne, err) } numDebugTwo, err := models.GetDebugTwoPeriodCount(beginTime, endTime) if err != nil { log.Error("GetDebugTwoCount failed(%s): %v", numDebugTwo, err) } numTrainTwo, err := models.GetTrainTwoPeriodCount(beginTime, endTime) if err != nil { log.Error("GetTrainTwoCount failed(%s): %v", numTrainTwo, err) } numInferenceTwo, err := models.GetInferenceTwoPeriodCount(beginTime, endTime) if err != nil { log.Error("GetInferenceTwoCount failed(%s): %v", numInferenceTwo, err) } numCloudOneAll := numDubugOne + numBenchmarkOne + numTrainOne numCloudTwoAll := numDebugTwo + numTrainTwo + numInferenceTwo durationDubugOne, err := models.GetDebugOnePeriodDuration(beginTime, endTime) if err != nil { log.Error("GetDebugOneDuration failed(%s): %v", durationDubugOne, err) } durationBenchmarkOne, err := models.GetBenchmarkOnePeriodDuration(beginTime, endTime) if err != nil { log.Error("GetBenchmarkOneDuration failed(%s): %v", durationBenchmarkOne, err) } durationTrainOne, err := models.GetTrainOnePeriodDuration(beginTime, endTime) if err != nil { log.Error("GetTrainOneDuration failed(%s): %v", durationTrainOne, err) } durationDebugTwo, err := models.GetDebugTwoPeriodDuration(beginTime, endTime) if err != nil { log.Error("GetDebugTwoDuration failed(%s): %v", durationDebugTwo, err) } durationTrainTwo, err := models.GetTrainTwoPeriodDuration(beginTime, endTime) if err != nil { log.Error("GetTrainTwoDuration failed(%s): %v", durationTrainTwo, err) } durationInferenceTwo, err := models.GetInferenceTwoPeriodDuration(beginTime, endTime) if err != nil { log.Error("GetInferenceTwoDuration failed(%s): %v", durationInferenceTwo, err) } durationCloudOneAll, err := models.GetCloudBrainOnePeriodDuration(beginTime, endTime) if err != nil { log.Error("GetCloudBrainOnePeriodDuration failed(%s): %v", durationCloudOneAll, err) } durationCloudTwoAll, err := models.GetCloudBrainTwoPeriodDuration(beginTime, endTime) if err != nil { log.Error("GetCloudBrainTwoPeriodDuration failed(%s): %v", durationCloudTwoAll, err) } err = models.CreateCloudbrainStatistic(&models.CloudbrainStatistic{ Date: date, WhichHour: whichHour, NumDubugOne: numDubugOne, NumBenchmarkOne: numBenchmarkOne, NumTrainOne: numTrainOne, NumDubugTwo: numDebugTwo, NumTrainTwo: numTrainTwo, NumInferenceTwo: numInferenceTwo, NumCloudOneAll: numCloudOneAll, NumCloudTwoAll: numCloudTwoAll, DurationDubugOne: durationDubugOne, DurationBenchmarkOne: durationBenchmarkOne, DurationTrainOne: durationTrainOne, DurationDebugTwo: durationDebugTwo, DurationTrainTwo: durationTrainTwo, DurationInferenceTwo: durationInferenceTwo, DurationCloudOneAll: durationCloudOneAll, DurationCloudTwoAll: durationCloudTwoAll, }) if err != nil { log.Error("CreateCloudbrainStatistic(%s) failed:%v", date, err.Error()) return } } }