Example #1
0
func (self *SrcManage) Push(req *context.Request) {
	if spiderId, ok := req.GetSpiderId(); ok {
		priority := int(req.GetPriority())
		if priority > MAX_PRIORITY {
			priority = MAX_PRIORITY
		}

		for i, x := 0, priority+1-len(self.queue[spiderId]); i < x; i++ {
			self.queue[spiderId] = append(self.queue[spiderId], []*context.Request{})
		}

		self.queue[spiderId][priority] = append(self.queue[spiderId][priority], req)
	}
}
Example #2
0
func (self *SrcManage) Push(req *context.Request) {
	spiderId, ok := req.GetSpiderId()
	if !ok {
		return
	}

	// 初始化该蜘蛛的队列
	if _, ok := self.queue[spiderId]; !ok {
		self.mutex[spiderId] = new(sync.Mutex)
		self.queue[spiderId] = make(map[int][]*context.Request)
	}

	priority := req.GetPriority()

	// 登记该蜘蛛下该优先级队列
	if _, ok := self.queue[spiderId][priority]; !ok {
		self.uIndex(spiderId, priority)
	}

	// 添加请求到队列
	self.queue[spiderId][priority] = append(self.queue[spiderId][priority], req)
}