-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (60 loc) · 1.31 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"os"
"strconv"
"github.com/Ansh1902396/cube/task"
"github.com/Ansh1902396/cube/worker"
"github.com/docker/docker/client"
"github.com/golang-collections/collections/queue"
"github.com/google/uuid"
)
func createContainer() (*task.Docker, *task.DockerResult) {
c := task.Config{
Name: "test-container-1",
Image: "postgres:13",
Env: []string{
"POSTGRES_USER=ansh",
"POSTGRES_PASSWORD=secret",
},
}
dc, _ := client.NewClientWithOpts(client.FromEnv)
d := task.Docker{
Client: dc,
Config: c,
}
result := d.Run()
if result.Error != nil {
fmt.Printf("%v\n", result.Error)
return nil, nil
}
fmt.Printf("Container is started")
return &d, &result
}
func stopContainer(d *task.Docker) *task.DockerResult {
result := d.Stop(d.ContainerId)
if result.Error != nil {
fmt.Printf("%v\n", result.Error)
return nil
}
fmt.Printf(
"Container %s has been stopped and removed\n", result.ContainerId)
return &result
}
func main() {
host := os.Getenv("TESSERACT_HOST")
port, _ := strconv.Atoi(os.Getenv("TESSERACT_PORT"))
fmt.Println("starting cube worker")
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()
}