Example #1
0
func queueRefiller(to chan<- task, st *db.ProxyStorage) {
	for {
		logger.Trace("Refilling proxy check queue")
		list, err := st.AscByLastUpdateTS(100)
		if err != nil {
			logger.Errf("Error while refilling proxy check queue. Error: %s", err)
		} else {
			for _, p := range list {
				logger.Tracef("Putting %s to check queue", p)
				t := task{p, []string{"http"}}
				to <- t
			}
		}
		time.Sleep(10 * time.Second)
	}
}
Example #2
0
func startWorker(in <-chan task, storage *db.ProxyStorage) {
	for {
		t := <-in
		logger.Tracef("Running checks [%v] for %v", t.checks, t.target)
		r, err := client.CheckProxy(t.target, t.checks)
		if err != nil {
			logger.Errf("Error while checking proxy %v. Error: %v", t.target, err)
			continue
		}
		logger.Tracef("Got check results for %v. Results: %v", t.target, r)

		t.target.LastUpdateTS = time.Now().Unix()
		t.target.Http = r.CheckResults["http"]
		t.target.Https = r.CheckResults["https"]
		t.target.Ping = r.Ping
		storage.SaveProxy(t.target, true)
	}
}