diff --git a/app/task/init.go b/app/task/init.go index e5347b0..df674b7 100644 --- a/app/task/init.go +++ b/app/task/init.go @@ -84,6 +84,7 @@ func doTask(fnName string) func() { // 增加自动任务队列 func initTasks() { - jobs[taskMd.DataCollectCronHaodankuRealNews] = taskDataCollectCronHaodankuRealNews // + jobs[taskMd.DataCollectCronHaodankuRealNews] = taskDataCollectCronHaodankuRealNews // + jobs[taskMd.DataCollectCronHaodankuRealNews10] = taskDataCollectCronHaodankuRealNews10 // } diff --git a/app/task/md/cron_key.go b/app/task/md/cron_key.go index 37586c5..d780827 100644 --- a/app/task/md/cron_key.go +++ b/app/task/md/cron_key.go @@ -1,5 +1,6 @@ package md const ( - DataCollectCronHaodankuRealNews = "data_collect_cron_haodanku_real_news" + DataCollectCronHaodankuRealNews = "data_collect_cron_haodanku_real_news" + DataCollectCronHaodankuRealNews10 = "data_collect_cron_haodanku_real_news10" ) diff --git a/app/task/svc/svc_data_collect_cron_haodanku_real_news.go b/app/task/svc/svc_data_collect_cron_haodanku_real_news.go index 1a7dbc8..11221f1 100644 --- a/app/task/svc/svc_data_collect_cron_haodanku_real_news.go +++ b/app/task/svc/svc_data_collect_cron_haodanku_real_news.go @@ -15,10 +15,15 @@ import ( "time" ) -func DataCollectCronHaodankuRealNews() { +func DataCollectCronHaodankuRealNews(types int) { key := md.ZhiosRealNewsData //es.CreateIndexIfNotExists(key, md.ZhiosRealNewsDataField) ids := []int{10001, 10002, 10003, 10004} + num := 10 + if types == 0 { + ids = []int{0} + num = 3 + } size := 100 now := time.Now() fmt.Println("============", time.Since(now)) @@ -27,7 +32,7 @@ func DataCollectCronHaodankuRealNews() { third_zm_app_key := sysCfgDb.SysCfgGetOneData("third_zm_app_key") third_zm_app_secret := sysCfgDb.SysCfgGetOneData("third_zm_app_secret") for _, v := range ids { - for i := 1; i <= 10; i++ { + for i := 1; i <= num; i++ { tianMaoChaoZhiData, err := haodanku.HaodankuRealTime(utils.IntToStr(v), utils.IntToStr(i), utils.IntToStr(size), "") if err != nil { return diff --git a/app/task/task_data_collect_cron_haodanku_real_news.go b/app/task/task_data_collect_cron_haodanku_real_news.go index f08f7f2..fab82a7 100644 --- a/app/task/task_data_collect_cron_haodanku_real_news.go +++ b/app/task/task_data_collect_cron_haodanku_real_news.go @@ -16,6 +16,6 @@ func taskDataCollectCronHaodankuRealNews() { } START: ch <- 1 - svc.DataCollectCronHaodankuRealNews() + svc.DataCollectCronHaodankuRealNews(1) <-ch } diff --git a/app/task/task_data_collect_cron_haodanku_real_news10.go b/app/task/task_data_collect_cron_haodanku_real_news10.go new file mode 100644 index 0000000..db35375 --- /dev/null +++ b/app/task/task_data_collect_cron_haodanku_real_news10.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskDataCollectCronHaodankuRealNews10() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.DataCollectCronHaodankuRealNews(0) + <-ch +}