diff --git a/modules/rtask/api_tasktest.go b/modules/rtask/api_tasktest.go index b43916ca1..ab6707a6a 100644 --- a/modules/rtask/api_tasktest.go +++ b/modules/rtask/api_tasktest.go @@ -50,9 +50,11 @@ func (this *apiComp) Rtest(session comm.IUserSession, req *pb.RtaskTestReq) (cod this.moduleRtask.modelRtask.Change(rtask.Uid, update) } else { - if code = this.moduleRtask.SendToRtask(session, comm.TaskType(req.RtaskType), req.Params...); code != pb.ErrorCode_Success { - rsp.Flag = false - } + this.moduleRtask.TriggerTask(session.GetUserId(), &comm.TaskParam{ + TT: comm.TaskType(req.RtaskType), + Params: req.Params, + }) + rsp.Flag = true } if err := session.SendMsg(string(this.moduleRtask.GetType()), "rtest", rsp); err != nil { diff --git a/modules/rtask/module.go b/modules/rtask/module.go index 1b29f2ced..89cc0eacc 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -218,8 +218,24 @@ func (this *ModuleRtask) initRtaskVerifyHandle() { } } -func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) { +// 处理触发的任务 +func (this *ModuleRtask) processOneTask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) { + uid := session.GetUserId() var condis []*rtaskCondi + + if this.IsCross() { + //随机任务 + if _, err := this.service.AcrossClusterRpcGo( + context.Background(), + session.GetServiecTag(), + comm.Service_Worker, + string(comm.Rpc_ModuleRtaskSendTask), + pb.RPCRTaskReq{Uid: uid, TaskType: int32(rtaskType), Param: params}, + nil); err != nil { + this.Errorln(err) + } + return + } for _, codiConf := range this.configure.getRtaskCondis(int32(rtaskType)) { v, ok := this.handleMap[codiConf.Id] if !ok { @@ -244,7 +260,6 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par condis = append(condis, v) } } - session, _ := this.GetUserSession(uid) // update for _, v := range condis { @@ -275,28 +290,11 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par if worldtask, ok := module.(comm.IWorldtask); ok { if err := worldtask.TaskcondNotify(session, conf.Id); err != nil { - var customErr = new(comm.CustomError) - if errors.As(err, &customErr) { - notifyErr := &pb.NotifyErrorNotifyPush{ - ReqMainType: string(comm.ModuleWorldtask), - ReqSubType: "finish", - Message: "", - } - - if customErr.Code == pb.ErrorCode_WorldtaskLvNotEnough { - notifyErr.Code = pb.ErrorCode_WorldtaskLvNotEnough - session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr) - } else if customErr.Code == pb.ErrorCode_UserSessionNobeing { - notifyErr.Code = pb.ErrorCode_UserSessionNobeing - session.SendMsg(string(comm.ModuleWorldtask), "finish", notifyErr) - } else { - log.Error("任务条件达成通知", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "condId", Value: conf.Id}, - log.Field{Key: "err", Value: err.Error()}, - ) - } - } + log.Error("任务条件达成通知", + log.Field{Key: "uid", Value: uid}, + log.Field{Key: "condId", Value: conf.Id}, + log.Field{Key: "err", Value: err.Error()}, + ) } } }() @@ -311,7 +309,7 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par }() // 公会 if user, ok := userModule.(comm.IUser); ok { - ex, err := user.GetUserExpand(session.GetUserId()) + ex, err := user.GetUserExpand(uid) if err == nil && ex.SociatyId != "" { sociatyModule, err := this.service.GetModule(comm.ModuleSociaty) if err != nil { @@ -326,11 +324,12 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par log.Field{Key: "err", Value: err2.Error()}, ) } - if module, err := this.service.GetModule(comm.ModuleRtask); err == nil { - if iRtask, ok := module.(comm.IRtask); ok { - iRtask.SendToRtask(session, comm.Rtype156, 1) - } - } + this.processOneTask(session, comm.Rtype156, 1) + // if module, err := this.service.GetModule(comm.ModuleRtask); err == nil { + // if iRtask, ok := module.(comm.IRtask); ok { + // iRtask.SendToRtask(session, comm.Rtype156, 1) + // } + // } } } } @@ -343,6 +342,7 @@ func (this *ModuleRtask) processOneTask(uid string, rtaskType comm.TaskType, par return } +// Deprecated func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.TaskType, params ...int32) (code pb.ErrorCode) { uid := session.GetUserId() if this.IsCross() { @@ -490,6 +490,20 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T } func (this *ModuleRtask) TriggerTask(uid string, taskParams ...*comm.TaskParam) { + session, ok := this.GetUserSession(uid) + if !ok { + return + } + for _, tp := range taskParams { + if code := this.processOneTask(session, tp.TT, tp.Params...); code != pb.ErrorCode_Success { + this.Debug("任务处理", + log.Field{Key: "uid", Value: uid}, + log.Field{Key: "taskType", Value: tp.TT}, + log.Field{Key: "params", Value: tp.Params}) + } + session.Push() + comm.PuttaskParam(tp) + } return } @@ -566,7 +580,7 @@ func (this *ModuleRtask) Rpc_ModuleRtaskSendTask(ctx context.Context, args *pb.R err = fmt.Errorf("未查询到用户:%s在线信息!", args.Uid) return } else { - this.SendToRtask(session, comm.TaskType(args.TaskType), args.Param...) + this.processOneTask(session, comm.TaskType(args.TaskType), args.Param...) session.Push() } return diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 19d037399..22eaa8281 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -123,7 +123,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c } if req.Figure != 0 { - this.module.ModuleRtask.SendToRtask(session, comm.Rtype72, 1) + this.module.ModuleRtask.TriggerTask(uid,&comm.TaskParam{TT:comm.Rtype72,Params: []int32{1}}) } this.mail.SendMailByCid(session, comm.Welcomemail, nil)