|
@@ -22,12 +22,17 @@ type JobManager struct {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+var (
|
|
|
|
+ activityUserJobRunning bool
|
|
|
|
+ bindPhoneAndSubAgainJobRunning bool
|
|
|
|
+)
|
|
|
|
+
|
|
func InitJobManager() *JobManager {
|
|
func InitJobManager() *JobManager {
|
|
var (
|
|
var (
|
|
err error
|
|
err error
|
|
ctx = gctx.New()
|
|
ctx = gctx.New()
|
|
- bindPhoneAndSubAgainCronStr = g.Cfg().MustGet(ctx, "bindPhoneAndSubAgain").String()
|
|
|
|
- activityUserCronStr = g.Cfg().MustGet(ctx, "activityUser").String()
|
|
|
|
|
|
+ bindPhoneAndSubAgainCronStr = g.Cfg().MustGet(ctx, "cron.bindPhoneAndSubAgain").String()
|
|
|
|
+ activityUserCronStr = g.Cfg().MustGet(ctx, "cron.activityUser").String()
|
|
)
|
|
)
|
|
|
|
|
|
job := &JobManager{
|
|
job := &JobManager{
|
|
@@ -37,6 +42,15 @@ func InitJobManager() *JobManager {
|
|
|
|
|
|
if bindPhoneAndSubAgainCronStr != "" {
|
|
if bindPhoneAndSubAgainCronStr != "" {
|
|
_, err = gcron.Add(ctx, bindPhoneAndSubAgainCronStr, func(ctx context.Context) {
|
|
_, err = gcron.Add(ctx, bindPhoneAndSubAgainCronStr, func(ctx context.Context) {
|
|
|
|
+ g.Log().Infof(ctx, "bindPhoneAndSubAgain start", bindPhoneAndSubAgainJobRunning)
|
|
|
|
+ if bindPhoneAndSubAgainJobRunning {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ bindPhoneAndSubAgainJobRunning = true
|
|
|
|
+ defer func() {
|
|
|
|
+ bindPhoneAndSubAgainJobRunning = false
|
|
|
|
+ }()
|
|
|
|
+
|
|
job.LoadPayUser()
|
|
job.LoadPayUser()
|
|
job.LoadAgainSubUser()
|
|
job.LoadAgainSubUser()
|
|
job.LoadBindPhoneUser()
|
|
job.LoadBindPhoneUser()
|
|
@@ -49,8 +63,18 @@ func InitJobManager() *JobManager {
|
|
|
|
|
|
if activityUserCronStr != "" {
|
|
if activityUserCronStr != "" {
|
|
_, err = gcron.Add(ctx, activityUserCronStr, func(ctx context.Context) {
|
|
_, err = gcron.Add(ctx, activityUserCronStr, func(ctx context.Context) {
|
|
|
|
+ g.Log().Infof(ctx, "activityUser start", activityUserJobRunning)
|
|
|
|
+ if activityUserJobRunning {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ activityUserJobRunning = true
|
|
|
|
+ defer func() {
|
|
|
|
+ activityUserJobRunning = false
|
|
|
|
+ }()
|
|
|
|
+
|
|
job.LoadPayUser()
|
|
job.LoadPayUser()
|
|
job.LoadActivityUser()
|
|
job.LoadActivityUser()
|
|
|
|
+
|
|
}, "activityUser")
|
|
}, "activityUser")
|
|
if err != nil {
|
|
if err != nil {
|
|
panic(err)
|
|
panic(err)
|
|
@@ -84,11 +108,13 @@ func (jm *JobManager) SaveLastRun() error {
|
|
}
|
|
}
|
|
|
|
|
|
func (jm *JobManager) LoadPayUser() {
|
|
func (jm *JobManager) LoadPayUser() {
|
|
|
|
+ g.Log().Infof(context.TODO(), "加载付费用户")
|
|
newMap := gmap.New(true)
|
|
newMap := gmap.New(true)
|
|
for i, v := range public.GetPayUser() {
|
|
for i, v := range public.GetPayUser() {
|
|
newMap.Set(i, v)
|
|
newMap.Set(i, v)
|
|
}
|
|
}
|
|
jm.payUser = newMap
|
|
jm.payUser = newMap
|
|
|
|
+ g.Dump(newMap)
|
|
}
|
|
}
|
|
|
|
|
|
func (jm *JobManager) FilterPayUserAndSaveDb(ctx context.Context, value interface{}) error {
|
|
func (jm *JobManager) FilterPayUserAndSaveDb(ctx context.Context, value interface{}) error {
|
|
@@ -99,25 +125,25 @@ func (jm *JobManager) FilterPayUserAndSaveDb(ctx context.Context, value interfac
|
|
operationTime string
|
|
operationTime string
|
|
)
|
|
)
|
|
if msg, ok := value.(*public.AgainSubUserMsg); ok {
|
|
if msg, ok := value.(*public.AgainSubUserMsg); ok {
|
|
- if jm.payUser.Contains(msg.MgoUserID) {
|
|
|
|
- return nil
|
|
|
|
- }
|
|
|
|
|
|
+ //if jm.payUser.Contains(msg.MgoUserID) {
|
|
|
|
+ // return nil
|
|
|
|
+ //}
|
|
operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
|
|
operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
|
|
- sql = `(mogUserId,sub_again_date,create_time)VALUES (?, ?, ?)ON DUPLICATE KEY UPDATE sub_again_date=?`
|
|
|
|
|
|
+ sql += `(mogUserId,sub_again_date,create_time)VALUES (?, ?, ?)ON DUPLICATE KEY UPDATE sub_again_date=?`
|
|
val = append(val, msg.MgoUserID, operationTime, now, operationTime)
|
|
val = append(val, msg.MgoUserID, operationTime, now, operationTime)
|
|
} else if msg, ok := value.(*public.BindMsg); ok {
|
|
} else if msg, ok := value.(*public.BindMsg); ok {
|
|
- if jm.payUser.Contains(msg.MgoUserID) {
|
|
|
|
- return nil
|
|
|
|
- }
|
|
|
|
|
|
+ //if jm.payUser.Contains(msg.MgoUserID) {
|
|
|
|
+ // return nil
|
|
|
|
+ //}
|
|
operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
|
|
operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
|
|
sql += `(mogUserId,phone,bind_phone_date,create_time)VALUES (?, ?, ?, ?)ON DUPLICATE KEY UPDATE phone=?, bind_phone_date=?`
|
|
sql += `(mogUserId,phone,bind_phone_date,create_time)VALUES (?, ?, ?, ?)ON DUPLICATE KEY UPDATE phone=?, bind_phone_date=?`
|
|
val = append(val, msg.MgoUserID, msg.Phone, operationTime, now, msg.Phone, operationTime)
|
|
val = append(val, msg.MgoUserID, msg.Phone, operationTime, now, msg.Phone, operationTime)
|
|
} else if msg, ok := value.(*public.NewActiveMsg); ok {
|
|
} else if msg, ok := value.(*public.NewActiveMsg); ok {
|
|
- if jm.payUser.Contains(msg.MgoUserID) {
|
|
|
|
- return nil
|
|
|
|
- }
|
|
|
|
|
|
+ //if jm.payUser.Contains(msg.MgoUserID) {
|
|
|
|
+ // return nil
|
|
|
|
+ //}
|
|
operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
|
|
operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
|
|
- sql = `(mogUserId,act_again_date,create_time)VALUES (?, ?, ?)ON DUPLICATE KEY UPDATE act_again_date=?`
|
|
|
|
|
|
+ sql += `(mogUserId,act_again_date,create_time)VALUES (?, ?, ?)ON DUPLICATE KEY UPDATE act_again_date=?`
|
|
val = append(val, msg.MgoUserID, operationTime, now, operationTime)
|
|
val = append(val, msg.MgoUserID, operationTime, now, operationTime)
|
|
} else {
|
|
} else {
|
|
return fmt.Errorf("未知类型")
|
|
return fmt.Errorf("未知类型")
|