-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.go
46 lines (43 loc) · 1.12 KB
/
connection.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
package elasticsearch
import (
"os"
"time"
"github.com/JSTOR-Labs/pep/api/globals"
"github.com/olivere/elastic/v7"
"github.com/spf13/viper"
)
func Connect() (err error) {
if viper.GetBool("runtime.flash_drive_mode") {
attempts := 0
for {
globals.ES, err = elastic.NewClient(
elastic.SetURL(viper.GetString("elasticsearch.address")),
elastic.SetSniff(viper.GetBool("elasticsearch.sniff")),
)
if err != nil {
//e.Logger.Errorf("Waiting for Elasticsearch to start...")
attempts++
if attempts == 12 {
//e.Logger.Error("Elasticsearch took too long to respond, giving up.")
//e.Logger.Error("You can close everything and try again, if the issue persists," +
// " please contact the JSTOR Labs team.")
time.Sleep(30 * time.Second)
os.Exit(1)
}
time.Sleep(10 * time.Second)
continue
}
break
}
} else {
globals.ES, err = elastic.NewClient(
elastic.SetURL(viper.GetString("elasticsearch.address")),
elastic.SetSniff(viper.GetBool("elasticsearch.sniff")),
)
if err != nil {
// e.Logger.Fatal("Unable to create ES client", err)
return
}
}
return
}