diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index fb639459f..61821f973 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -246,7 +246,7 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus return userBusinessAnalysisReturnList, count } -func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, endTime time.Time, isReCount bool) { +func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, endTime time.Time, isReCount bool) error { log.Info("start to count other user info data") sess := x.NewSession() @@ -394,9 +394,13 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, dateRecord.CommitModelCount = 0 - statictisSess.Insert(&dateRecord) + _, err = statictisSess.Insert(&dateRecord) + if err != nil { + log.Info("insert daterecord failed." + err.Error()) + return err + } } - + return nil } func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime time.Time) { diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 134896177..8edecf836 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/services/mailer" "github.com/360EntSecGroup-Skylar/excelize/v2" ) @@ -142,10 +143,11 @@ func TimingCountDataByDateAndReCount(date string, isReCount bool) { //query wiki data log.Info("start to time count data") wikiMap := make(map[string]int) - + warnEmailMessage := "用户统计信息入库失败,请尽快定位。" repoList, err := models.GetAllRepositories() if err != nil { - log.Error("query repo error.") + log.Error("query repo error." + err.Error()) + mailer.SendWarnNotifyMail(setting.Warn_Notify_Mails, warnEmailMessage) return } log.Info("start to query wiki data") @@ -180,7 +182,11 @@ func TimingCountDataByDateAndReCount(date string, isReCount bool) { } } //other user info data - models.CounDataByDateAndReCount(wikiMap, startTime, endTime, isReCount) + err = models.CounDataByDateAndReCount(wikiMap, startTime, endTime, isReCount) + if err != nil { + log.Error("count user info error." + err.Error()) + mailer.SendWarnNotifyMail(setting.Warn_Notify_Mails, warnEmailMessage) + } } func TimingCountDataByDate(date string) {