-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
60 lines (48 loc) · 1.15 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
package main
import (
"context"
"time"
)
var makeInstanceInterval = 60 * time.Second
var pendingInstanceUInterval = 60 * time.Second
var (
AVAILABILITY_CHECK_TIME = time.Duration(60) * time.Second
)
func main() {
ctx := context.Background()
//region Database
var err error
ctx, err = DatabaseOpen(ctx)
if err != nil {
Logger.Fatalf("failed to setup database: %v", err)
}
defer func(ctx context.Context) {
err = DatabaseClose(ctx)
if err != nil {
Logger.Fatalf("failed to shutdown database: %v", err)
}
}(ctx)
for {
err = CheckAvailabilitySpotInstance(ctx)
if err != nil {
Logger.Errorf("failed to check spot availability instance: %v", err)
return
}
err = CheckAvailabilityOnDemandInstance(ctx)
if err != nil {
Logger.Errorf("failed to check on-demand availability instance: %v", err)
return
}
err = UpdateOccupiedInstance(ctx)
if err != nil {
Logger.Errorf("failed to update occupied instance: %v", err)
return
}
err = TerminateClosedSessionsInstance(ctx)
if err != nil {
Logger.Errorf("failed to terminate closed session instance: %v", err)
return
}
time.Sleep(AVAILABILITY_CHECK_TIME)
}
}