Example #1
0
func (this *ReqQiushiModule) Run(inner_data *context.Context, bschan *chan bool) {
	defer func() {
		if len(inner_data.BaiduAds) == 0 {
			*bschan <- false
		} else {
			*bschan <- true
		}
		utils.DebugLog.Write("reqqiushi set chan")
	}()
	var req_flag [int(MaxAdType)]bool
	var req_chan [int(MaxAdType)](chan bool)
	var ret_ads [int(MaxAdType)][]context.AdInfo
	for i := 0; i < int(MaxAdType); i++ {
		req_flag[i] = false
	}
	switch inner_data.Req.AdSlot.AdSlotType {
	case context.AdSlotType_BANNER:
		req_chan[int(Banner)] = make(chan bool)
		go this.request(inner_data, Banner, &ret_ads[int(Banner)], &req_chan[int(Banner)])
		req_flag[int(Banner)] = true
	case context.AdSlotType_INITIALIZATION:
		//		req_chan[int(Initlization)] = make(chan bool)
		//		go this.request(inner_data, Initlization, &ret_ads[int(Initlization)], &req_chan[int(Initlization)])
		//		req_flag[int(Initlization)] = true
		req_chan[int(Insert)] = make(chan bool)
		go this.request(inner_data, Insert, &ret_ads[int(Insert)], &req_chan[Insert])
		req_flag[int(Insert)] = true
	case context.AdSlotType_INSERT:
		req_chan[int(Insert)] = make(chan bool)
		go this.request(inner_data, Insert, &ret_ads[int(Insert)], &req_chan[Insert])
		req_flag[int(Insert)] = true
	}
	for i := 0; i < int(MaxAdType); i++ {
		if req_flag[i] == true {
			select {
			case <-req_chan[i]:
				//			close(this.req_chan[i])
				// 填入队列
				utils.DebugLog.Write("get ret_ads . adtype[%d] ads_ret[%d]", i, len(ret_ads[i]))
				for j := 0; j < len(ret_ads[i]); j++ {
					inner_data.BaiduAds = append(inner_data.BaiduAds, ret_ads[i][j])
				}
			case <-time.After(time.Millisecond * time.Duration(this.timeout)):
				utils.WarningLog.Write("req qiushi reqtype[%d] timeout", i)
			}
		}
	}
	return
}