-
Notifications
You must be signed in to change notification settings - Fork 13
/
queue_downloader.go
62 lines (49 loc) · 1.66 KB
/
queue_downloader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package client
import (
"log"
"time"
"github.com/richo/roving/types"
)
// QueueDownloader periodically downloads the queues of all the fuzzers in
// the roving cluster from the server. It writes them to disk using the
// FleetFileManager. Because all clients on a client machine share the same
// FleetFileManager, we only need to run 1 QueueDownloader per client machin.
type QueueDownloader struct {
Interval time.Duration
Server *RovingServerClient
fileManager *types.FleetFileManager
}
// run runs the QueueDownloader periodically forever. It should never return.
func (q *QueueDownloader) run() {
ticker := time.NewTicker(q.Interval)
for {
select {
case <-ticker.C:
q.downloadQueues()
}
}
}
// downloadQueues downloads the queues from the roving server and saves them
// to disk.
func (q *QueueDownloader) downloadQueues() {
log.Printf("Downloading the queues")
// We don't need any metric tags for now
metricTags := make(map[string]string)
queues, err := q.Server.FetchQueues()
if err != nil {
// Fail without panicking so that we can retry in the
// next QueueDownloader cycle.
log.Printf("Error downloading queue err=%v", err)
types.SubmitMetricCount("queue_downloader.download_queue.fail", 1, metricTags)
return
}
log.Printf("Writing queues to disk")
if err = q.fileManager.WriteQueues(queues); err != nil {
// Fail without panicking so that we can retry in the
// next QueueDownloader cycle.
log.Printf("Error writing queue to disk err=%v", err)
types.SubmitMetricCount("queue_downloader.download_queue.fail", 1, metricTags)
return
}
types.SubmitMetricCount("queue_downloader.download_queue.success", 1, metricTags)
}