-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathmain.go
More file actions
72 lines (58 loc) · 1.67 KB
/
main.go
File metadata and controls
72 lines (58 loc) · 1.67 KB
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
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
"github.com/yetanotherco/aligned_layer/aggregator/pkg"
"github.com/yetanotherco/aligned_layer/core/config"
)
var (
// Version is the version of the binary.
Version string
GitCommit string
GitDate string
)
var flags = []cli.Flag{
config.ConfigFileFlag,
}
func main() {
app := cli.NewApp()
app.Flags = flags
app.Version = fmt.Sprintf("%s-%s-%s", Version, GitCommit, GitDate)
app.Name = "aligned-layer-aggregator"
app.Usage = "Aligned Layer Aggregator"
app.Description = "Service that aggregates signed responses from operator nodes."
app.Action = aggregatorMain
err := app.Run(os.Args)
if err != nil {
log.Fatalln("Application failed.", "Message:", err)
}
}
func aggregatorMain(ctx *cli.Context) error {
configFilePath := ctx.String(config.ConfigFileFlag.Name)
aggregatorConfig := config.NewAggregatorConfig(configFilePath)
aggregator, err := pkg.NewAggregator(*aggregatorConfig)
if err != nil {
aggregatorConfig.BaseConfig.Logger.Error("Cannot create aggregator", "err", err)
return err
}
// Supervisor revives garbage collector
go func() {
for {
log.Println("Starting Garbage collector")
aggregator.ClearTasksFromMaps()
log.Println("Garbage collector panicked, Supervisor restarting")
}
}()
// Listen for new task created in the ServiceManager contract in a separate goroutine, both V1 and V2 subscriptions:
go func() {
listenErrPair := aggregator.SubscribeToNewTasks()
if listenErrPair != nil {
aggregatorConfig.BaseConfig.Logger.Fatal("Error subscribing for new tasks", "err", listenErrPair)
}
}()
err = aggregator.Start(context.Background())
return err
}