forked from stellar/quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
travis.go
53 lines (43 loc) · 861 Bytes
/
travis.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
package main
import (
"encoding/json"
"log"
"net/http"
"os"
"time"
)
const timeout = 1 * time.Hour
type Root struct {
HorizonSequence int32 `json:"history_latest_ledger"`
CoreSequence int32 `json:"core_latest_ledger"`
}
func main() {
startTime := time.Now()
for {
time.Sleep(10 * time.Second)
logLine("Waiting for Horizon to start ingesting")
if time.Since(startTime) > timeout {
logLine("Timeout")
os.Exit(-1)
}
resp, err := http.Get("http://localhost:8000")
if err != nil {
logLine(err)
continue
}
var root Root
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&root)
if err != nil {
logLine(err)
continue
}
if root.HorizonSequence > 0 {
logLine("Horizon started ingesting!")
os.Exit(0)
}
}
}
func logLine(text interface{}) {
log.Println("\033[32;1m[test]\033[0m", text)
}