-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
93 lines (80 loc) · 2.08 KB
/
main.go
File metadata and controls
93 lines (80 loc) · 2.08 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"slices"
"syscall"
"api.audius.co/api"
"api.audius.co/config"
"api.audius.co/ddl"
"api.audius.co/esindexer"
core_indexer "api.audius.co/indexer"
solana_indexer "api.audius.co/solana/indexer"
)
func main() {
command := "server"
if len(os.Args) > 1 {
command = os.Args[1]
}
if !config.Cfg.RunMigrations && command != "migrate" {
fmt.Println("Skipping migrations. Set env runMigrations=true to run.")
} else {
fmt.Println("Running migrations...")
ddl.RunMigrations()
}
switch command {
case "server":
{
fmt.Println("Running server...")
as := api.NewApiServer(config.Cfg)
as.Serve()
}
case "indexer":
{
fmt.Println("Running indexer...")
indexer := core_indexer.NewIndexer(config.Cfg)
defer indexer.Close()
// Capture termination signals for graceful shutdown of the indexer
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGINT, os.Interrupt)
defer stop()
if err := indexer.Start(ctx); err != nil {
if !errors.Is(err, context.Canceled) {
panic(err)
}
}
}
case "es-indexer":
{
collections := os.Args[2:]
drop := slices.Contains(collections, "drop")
fmt.Printf("Reindexing ElasticSearch (collections=%s, drop=%t)...\n", collections, drop)
esindexer.ReindexLegacy(drop, collections...)
}
case "solana-indexer":
{
fmt.Println("Running solana-indexer...")
solanaIndexer := solana_indexer.New(config.Cfg)
defer solanaIndexer.Close()
healthServer := solana_indexer.NewServer(solanaIndexer)
// Capture termination signals for graceful shutdown of the indexer
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGINT, os.Interrupt)
defer stop()
go healthServer.Start(ctx)
if err := solanaIndexer.Start(ctx); err != nil {
if !errors.Is(err, context.Canceled) {
panic(err)
}
}
}
case "migrate":
{
// no-op, handled prior to switch/case
os.Exit(0)
}
default:
fmt.Printf("Unrecognized command: %s", command)
}
}