Ejemplo n.º 1
0
Archivo: app.go Proyecto: Cdim/pholcus
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.MaxPage = self.AppConf.MaxPage
	task.ProxyMinute = self.AppConf.ProxyMinute
	task.Keywords = self.AppConf.Keywords
}
Ejemplo n.º 2
0
// 服务器模式下,生成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
}