-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (47 loc) · 1.08 KB
/
main.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
package main
import (
"flag"
"log"
"orchestra/task"
"orchestra/worker"
"time"
"github.com/golang-collections/collections/queue"
"github.com/google/uuid"
)
var (
Host string
Port int
)
func setupFlags() {
flag.StringVar(&Host, "host", "localhost", "Host on which orchestra runs")
flag.IntVar(&Port, "port", 7777, "port to run orchestra")
}
//TODO: Check the goprocinfo libarary to update `stats.go`
// ioutil.ReadFile(path) code.
func main() {
setupFlags()
// host := os.Getenv("ORCHESTRA_HOST")
// port, _ := strconv.Atoi(os.Getenv("ORCHESTRA_PORT"))
w := worker.Worker{
Queue: *queue.New(),
Db: make(map[uuid.UUID]*task.Task),
}
api := worker.API{Address: Host, Port: Port, Worker: &w}
go runTasks(&w)
go w.CollectStats()
api.Start()
}
func runTasks(w *worker.Worker) {
for {
if w.Queue.Len() != 0 {
result := w.RunTask()
if result.Error != nil {
log.Printf("Error running task: %s", result.Error)
}
} else {
log.Printf("No task found to be processed in the queue.")
}
log.Println("sleeping for 10 seconds.")
time.Sleep(10 * time.Second)
}
}