| @@ -26,7 +26,7 @@ func GetJobOperateTypeFromCloudbrainStatus(cloudbrain *models.Cloudbrain) JobOpe | |||||
| return "" | return "" | ||||
| } | } | ||||
| func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Cloudbrain, date time.Time) error { | |||||
| func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Cloudbrain) error { | |||||
| defer func() { | defer func() { | ||||
| if err := recover(); err != nil { | if err := recover(); err != nil { | ||||
| combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2)) | combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2)) | ||||
| @@ -42,9 +42,6 @@ func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Clou | |||||
| return nil | return nil | ||||
| } | } | ||||
| if date.IsZero() { | |||||
| date = time.Now() | |||||
| } | |||||
| openId := models.GetUserWechatOpenId(cloudbrain.UserID) | openId := models.GetUserWechatOpenId(cloudbrain.UserID) | ||||
| if openId == "" { | if openId == "" { | ||||
| return errors.New("Wechat openId not exist") | return errors.New("Wechat openId not exist") | ||||
| @@ -53,7 +50,7 @@ func SendCloudbrainStartedMsg(operateType JobOperateType, cloudbrain models.Clou | |||||
| First: TemplateValue{Value: getCloudbrainTemplateTitle(operateType)}, | First: TemplateValue{Value: getCloudbrainTemplateTitle(operateType)}, | ||||
| Keyword1: TemplateValue{Value: cloudbrain.DisplayJobName}, | Keyword1: TemplateValue{Value: cloudbrain.DisplayJobName}, | ||||
| Keyword2: TemplateValue{Value: getJobTypeDisplayName(cloudbrain.JobType)}, | Keyword2: TemplateValue{Value: getJobTypeDisplayName(cloudbrain.JobType)}, | ||||
| Keyword3: TemplateValue{Value: date.Format("2006-01-02 15:04:05")}, | |||||
| Keyword3: TemplateValue{Value: time.Unix(int64(cloudbrain.CreatedUnix), 0).Format("2006-01-02 15:04:05")}, | |||||
| Remark: TemplateValue{Value: getCloudbrainTemplateRemark(operateType)}, | Remark: TemplateValue{Value: getCloudbrainTemplateRemark(operateType)}, | ||||
| } | } | ||||
| req := TemplateMsgRequest{ | req := TemplateMsgRequest{ | ||||
| @@ -8,7 +8,7 @@ import ( | |||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| "code.gitea.io/gitea/modules/auth/wechat" | "code.gitea.io/gitea/modules/auth/wechat" | ||||
| "code.gitea.io/gitea/modules/notification/base" | "code.gitea.io/gitea/modules/notification/base" | ||||
| "time" | |||||
| "code.gitea.io/gitea/modules/setting" | |||||
| ) | ) | ||||
| type wechatNotifier struct { | type wechatNotifier struct { | ||||
| @@ -31,8 +31,14 @@ func (*wechatNotifier) NotifyChangeCloudbrainStatus(cloudbrain *models.Cloudbrai | |||||
| } | } | ||||
| switch operateType { | switch operateType { | ||||
| case wechat.JobOperateTypeStart: | case wechat.JobOperateTypeStart: | ||||
| if cloudbrain.JobType == string(models.JobTypeDebug) { | |||||
| go wechat.SendCloudbrainStartedMsg(operateType, *cloudbrain, time.Unix(int64(cloudbrain.StartTime), 0)) | |||||
| if len(setting.CloudbrainStartedNotifyList) == 0 { | |||||
| return | |||||
| } | |||||
| for _, v := range setting.CloudbrainStartedNotifyList { | |||||
| if v == cloudbrain.JobType { | |||||
| go wechat.SendCloudbrainStartedMsg(operateType, *cloudbrain) | |||||
| return | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -584,6 +584,7 @@ var ( | |||||
| //wechat template msg config | //wechat template msg config | ||||
| CloudbrainStartedTemplateId string | CloudbrainStartedTemplateId string | ||||
| CloudbrainStartedNotifyList []string | |||||
| //nginx proxy | //nginx proxy | ||||
| PROXYURL string | PROXYURL string | ||||
| @@ -1444,6 +1445,7 @@ func NewContext() { | |||||
| TreePathOfAutoMsgReply = sec.Key("AUTO_REPLY_TREE_PATH").MustString("wechat/auto_reply.json") | TreePathOfAutoMsgReply = sec.Key("AUTO_REPLY_TREE_PATH").MustString("wechat/auto_reply.json") | ||||
| TreePathOfSubscribe = sec.Key("SUBSCRIBE_TREE_PATH").MustString("wechat/subscribe_reply.json") | TreePathOfSubscribe = sec.Key("SUBSCRIBE_TREE_PATH").MustString("wechat/subscribe_reply.json") | ||||
| CloudbrainStartedTemplateId = sec.Key("CLOUDBRAIN_STARTED_TEMPLATE_ID").MustString("") | CloudbrainStartedTemplateId = sec.Key("CLOUDBRAIN_STARTED_TEMPLATE_ID").MustString("") | ||||
| CloudbrainStartedNotifyList = strings.Split(sec.Key("CLOUDBRAIN_STARTED_NOTIFY_LIST").MustString("DEBUG"), ",") | |||||
| SetRadarMapConfig() | SetRadarMapConfig() | ||||