Ejemplo n.º 1
0
func Load(url string) *entity.Task {
	response, err_con := util.GetUrlInUserAgent(url)
	task := &entity.Task{}
	if err_con != nil {
		util.ERROR("connect ERROR, %s", err_con)
		util.Connect()
	} else {
		defer response.Body.Close()
		body, _ := ioutil.ReadAll(response.Body)
		json.Unmarshal(body, &task)
		task.Size = len(task.Users)
		las_modify, err_parse := time.Parse(time.RFC1123, response.Header.Get("Last-Modified"))
		if err_parse != nil {
			util.ERROR("Parse time is ERROR: %s", err_parse)
		} else {
			if las_modify.After(LAST_MODIFIED) {
				if LAST_MODIFIED.IsZero() {
					util.INFO("Last-Modified is NULL, program is first run, Last-Modifyed: %s", las_modify)
				} else {
					util.INFO("file is change, Last-Modifyed: %s", las_modify)
				}
				LAST_MODIFIED = las_modify
				if task.Start {
					IS_WORKER = true
					util.INFO("start worker!")
				} else {
					IS_WORKER = false
					util.INFO("worker is not start!")
				}
			}
		}
	}
	return task
}
Ejemplo n.º 2
0
func OpenBrowser(filename string) {
	runtime.Gosched()
	cmd := exec.Command(BROWSER_PATH, filename)
	err_run := cmd.Run()
	if err_run != nil {
		util.ERROR("start browser file [%s] ERROR: %s", filename, err_run)
	}
}
Ejemplo n.º 3
0
func start() {
	runtime.Gosched()
	util.INFO("start ....")
	var user *entity.User
	for {
		if QUEUE.Len() > 0 {
			task := QUEUE.Back()
			user = task.Value.(*entity.User)
			if _, ok := CURRENT_TASK[fmt.Sprintf(FMT, user.UserName, user.Trigger)]; ok {
				filename := fmt.Sprintf("%s", util.HtmlFile(user))
				util.INFO("open browser file: %s", filename)
				go OpenBrowser(filename)
			} else {
				util.ERROR("task is removed, username: %s, trigger: %d", user.UserName, user.Trigger)
			}
			QUEUE.Remove(task)
			delete(CURRENT_TASK, fmt.Sprintf(FMT, user.UserName, user.Trigger))
		} else {
			time.Sleep(time.Duration(10) * time.Second)
		}
		time.Sleep(time.Duration(5) * time.Second)
	}
}