|
@@ -23,9 +23,10 @@ const (
|
|
|
|
|
|
// CustomManager 定制化报告管理
|
|
|
type CustomManager struct {
|
|
|
- Conf vars.CustomConfig
|
|
|
- UserGroup map[string]int // 月活用户
|
|
|
- BatchFlag string // 批次标识
|
|
|
+ Conf vars.CustomConfig
|
|
|
+ UserGroup map[string]int // 月活用户
|
|
|
+ BatchFlag string // 批次标识
|
|
|
+ IsSearchTime bool // 是否是运行时间段
|
|
|
sync.RWMutex
|
|
|
}
|
|
|
|
|
@@ -45,10 +46,8 @@ func InitCustomManager(conf vars.CustomConfig) *CustomManager {
|
|
|
Conf: conf,
|
|
|
UserGroup: make(map[string]int),
|
|
|
}
|
|
|
- //圈用户
|
|
|
+ //定时任务
|
|
|
go manager.ScheduledTasks()
|
|
|
- //执行查询
|
|
|
- go manager.DoSearch()
|
|
|
return manager
|
|
|
}
|
|
|
|
|
@@ -83,6 +82,7 @@ func (this *CustomManager) GetData(userId, keyWords string, isNew bool) map[stri
|
|
|
|
|
|
// ScheduledTasks 定时任务
|
|
|
func (this *CustomManager) ScheduledTasks() {
|
|
|
+ // 定时圈用户
|
|
|
if this.Conf.UpdateCron != "" {
|
|
|
c := cron.New(cron.WithSeconds())
|
|
|
// 给对象增加定时任务
|
|
@@ -91,15 +91,38 @@ func (this *CustomManager) ScheduledTasks() {
|
|
|
}
|
|
|
c.Run()
|
|
|
}
|
|
|
+ // 查询时间段限时
|
|
|
+ if this.Conf.SearchLimit.Switch.Start != "" && this.Conf.SearchLimit.Switch.Stop != "" {
|
|
|
+ //开始
|
|
|
+ startJob := cron.New(cron.WithSeconds())
|
|
|
+ if _, err := startJob.AddFunc(this.Conf.UpdateCron, func() {
|
|
|
+ this.IsSearchTime = true
|
|
|
+ go this.DoSearch()
|
|
|
+ }); err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ startJob.Run()
|
|
|
+ //结束
|
|
|
+ endJob := cron.New(cron.WithSeconds())
|
|
|
+ if _, err := endJob.AddFunc(this.Conf.UpdateCron, func() {
|
|
|
+ this.IsSearchTime = false
|
|
|
+ }); err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ endJob.Run()
|
|
|
+ } else {
|
|
|
+ go this.DoSearch()
|
|
|
+ }
|
|
|
//首次运行圈选用户
|
|
|
this.UpdateUserGroupJob()
|
|
|
}
|
|
|
|
|
|
// UpdateUserGroupJob 更新用户群组
|
|
|
func (this *CustomManager) UpdateUserGroupJob() {
|
|
|
- if this.Conf.Prop <= 0 {
|
|
|
+ if !this.Conf.Open {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
log.Printf("[MANAGER-INFO]CustomManager UserGroup Change Start\n")
|
|
|
//更新批次标识
|
|
|
this.BatchFlag = public.GetWeekBatchName(time.Now())
|
|
@@ -186,9 +209,14 @@ func (this *CustomManager) activityUserQueue(batchFlag string, userIds []string)
|
|
|
|
|
|
// DoSearch 定制化分析报告查询队列
|
|
|
func (this *CustomManager) DoSearch() {
|
|
|
+ log.Printf("[MANAGER-INFO]CustomManager DoSearch Start\n")
|
|
|
for {
|
|
|
//是否在可执行时间段内
|
|
|
- //???
|
|
|
+ if this.IsSearchTime {
|
|
|
+ log.Printf("[MANAGER-INFO]CustomManager DoSearch End\n")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
var obj *SearchEntity
|
|
|
select { //优先级 newRegisterUserQueue > activityUserQueue
|
|
|
case obj = <-newRegisterUserQueue:
|
|
@@ -204,7 +232,12 @@ func (this *CustomManager) DoSearch() {
|
|
|
continue
|
|
|
}
|
|
|
//查询结果处理
|
|
|
+ searchStart := time.Now()
|
|
|
data := search.PotentialCustomizeAnalysis(obj.UserId, obj.Value)
|
|
|
+ //查询超时,则休息一下
|
|
|
+ if time.Now().Sub(searchStart).Seconds() > float64(this.Conf.SearchLimit.TimeOver) {
|
|
|
+ time.Sleep(time.Second * time.Duration(this.Conf.SearchLimit.WaitTime))
|
|
|
+ }
|
|
|
if data == nil || len(data) == 0 {
|
|
|
log.Printf("[MANAGER-ERR]CustomManager %s DoSearch %s Is Empty\n", obj.UserId, obj.Value)
|
|
|
continue
|