in experiments/client_traffic_ctrl_tasks.go [171:206]
func (e *ExperimentClient) CheckIfTrafficControlTargetIsEnabled(env string, targetId int, currentTimestamp int64) bool {
if currentTimestamp == 0 {
currentTimestamp = time.Now().Unix()
}
var data = make(map[string][]model.TrafficControlTask, 0)
if env == common.Environment_Prepub_Desc {
data = e.prepubSceneTrafficControlTaskData
} else if env == common.Environment_Product_Desc {
data = e.productSceneTrafficControlTaskData
} else {
return false
}
for _, sceneTraffics := range data {
for _, traffic := range sceneTraffics {
for _, target := range traffic.TrafficControlTargets {
tid, err := strconv.Atoi(target.TrafficControlTargetId)
if err != nil {
e.logError(fmt.Errorf("traffic control targetId is illegal"))
}
if tid == targetId {
startTime, _ := time.Parse(time.RFC3339, target.StartTime)
endTime, _ := time.Parse(time.RFC3339, target.EndTime)
if target.Status == common.TrafficControlTargets_Status_Open && startTime.Unix() < currentTimestamp && currentTimestamp < endTime.Unix() {
return true
}
}
}
}
}
return false
}