func (self *Logic) setTask(task *distribute.Task) { task.ThreadNum = self.AppConf.ThreadNum task.Pausetime = self.AppConf.Pausetime task.OutType = self.AppConf.OutType task.DockerCap = self.AppConf.DockerCap task.DockerQueueCap = self.AppConf.DockerQueueCap task.SuccessInherit = self.AppConf.SuccessInherit task.FailureInherit = self.AppConf.FailureInherit task.Limit = self.AppConf.Limit task.ProxyMinute = self.AppConf.ProxyMinute task.Keyins = self.AppConf.Keyins }
// 服务器模式下,生成task并添加至库 func (self *Logic) addNewTask() (tasksNum, spidersNum int) { length := self.SpiderQueue.Len() t := distribute.Task{} // 从配置读取字段 t.ThreadNum = self.AppConf.ThreadNum t.Pausetime = self.AppConf.Pausetime t.OutType = self.AppConf.OutType t.DockerCap = self.AppConf.DockerCap t.DockerQueueCap = self.AppConf.DockerQueueCap t.InheritDeduplication = self.AppConf.InheritDeduplication t.DeduplicationTarget = self.AppConf.DeduplicationTarget t.MaxPage = self.AppConf.MaxPage t.Keywords = self.AppConf.Keywords for i, sp := range self.SpiderQueue.GetAll() { t.Spiders = append(t.Spiders, map[string]string{"name": sp.GetName(), "keyword": sp.GetKeyword()}) spidersNum++ // 每十个蜘蛛存为一个任务 if i > 0 && i%10 == 0 && length > 10 { // 存入 one := t self.TaskJar.Push(&one) // logs.Log.Notice(" * [新增任务] 详情: %#v", *t) tasksNum++ // 清空spider t.Spiders = []map[string]string{} } } if len(t.Spiders) != 0 { // 存入 one := t self.TaskJar.Push(&one) tasksNum++ } return }
// 服务器模式下,生成task并添加至库 func (self *Logic) addNewTask() (tasksNum, spidersNum int) { length := self.SpiderQueue.Len() t := distribute.Task{} // 从配置读取字段 t.ThreadNum = cache.Task.ThreadNum t.Pausetime = cache.Task.Pausetime t.OutType = cache.Task.OutType t.DockerCap = cache.Task.DockerCap t.DockerQueueCap = cache.Task.DockerQueueCap t.MaxPage = cache.Task.MaxPage for i, sp := range self.SpiderQueue.GetAll() { t.Spiders = append(t.Spiders, map[string]string{"name": sp.GetName(), "keyword": sp.GetKeyword()}) spidersNum++ // 每十个蜘蛛存为一个任务 if i > 0 && i%10 == 0 && length > 10 { // 存入 one := t self.TaskJar.Push(&one) // log.Printf(" * [新增任务] 详情: %#v", *t) tasksNum++ // 清空spider t.Spiders = []map[string]string{} } } if len(t.Spiders) != 0 { // 存入 one := t self.TaskJar.Push(&one) // log.Printf(" * [新增任务] 详情: %#v", *t) tasksNum++ } return }