-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.go
58 lines (47 loc) · 1.21 KB
/
instance.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
package coordinator
import (
"sync"
"github.com/myrteametrics/myrtea-sdk/v5/modeler"
"go.uber.org/zap"
)
// Instance represents a functional Myrtea instance
type Instance struct {
Initialized bool
Name string
Urls []string
LogicalIndices map[string]LogicalIndex
}
var (
_instance *Instance
_once sync.Once
)
func GetInstance() *Instance {
return _instance
}
func (i *Instance) LogicalIndex(modelName string) LogicalIndex {
return i.LogicalIndices[modelName]
}
func InitInstance(instanceName string, models map[int64]modeler.Model) error {
zap.L().Info("Initialize coordinator instance", zap.String("instanceName", instanceName))
instance := &Instance{
Initialized: false,
Name: instanceName,
LogicalIndices: make(map[string]LogicalIndex),
}
for _, model := range models {
var err error
var logicalIndex LogicalIndex
switch model.ElasticsearchOptions.Rollmode {
case "cron":
logicalIndex, err = NewLogicalIndexCron(instance.Name, model)
case "timebased":
logicalIndex, err = NewLogicalIndexTimeBased(instance.Name, model)
}
if err != nil {
return err
}
instance.LogicalIndices[model.Name] = logicalIndex
}
_instance = instance
return nil
}