Skip to content

Tweak booting order and update workflow #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml → .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pull Request
name: Run on Push

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
description: tag the release
required: true

name: Latest Release
name: Public A Release

defaults:
run:
Expand Down
15 changes: 7 additions & 8 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ func (agg *Aggregator) init() {
}

func (agg *Aggregator) Start(ctx context.Context) error {
agg.status = runningStatus

agg.logger.Infof("Starting aggregator %s", version.Get())

agg.init()
Expand All @@ -244,16 +242,17 @@ func (agg *Aggregator) Start(ctx context.Context) error {
}

agg.logger.Infof("Starting Task engine")
go agg.startTaskEngine(ctx)

agg.logger.Info("Starting repl")
go agg.startRepl()
agg.startTaskEngine(ctx)

agg.logger.Infof("Starting rpc server")
go agg.startRpcServer(ctx)
agg.startRpcServer(ctx)

agg.logger.Info("Starting repl")
agg.startRepl()

agg.logger.Infof("Starting http server")
go agg.startHttpServer(ctx)
agg.startHttpServer(ctx)
agg.status = runningStatus

// Setup wait signal
sigs := make(chan os.Signal, 1)
Expand Down
10 changes: 8 additions & 2 deletions aggregator/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func (agg *Aggregator) startHttpServer(ctx context.Context) {
e := echo.New()

e.GET("/up", func(c echo.Context) error {
return c.String(http.StatusOK, "AvaProtocol is up")
if agg.status == runningStatus {
return c.String(http.StatusOK, "up")
}

return c.String(http.StatusServiceUnavailable, "pending...")
})

e.GET("/operator", func(c echo.Context) error {
Expand All @@ -51,5 +55,7 @@ func (agg *Aggregator) startHttpServer(ctx context.Context) {
return c.HTMLBlob(http.StatusOK, buf.Bytes())
})

e.Logger.Fatal(e.Start(":1323"))
go func() {
e.Logger.Fatal(e.Start(":1323"))
}()
}
24 changes: 13 additions & 11 deletions aggregator/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ func (agg *Aggregator) startRepl() {
return
}

for {
if agg.IsShutdown() {
return
}
conn, err := repListener.Accept()
if err != nil {
log.Println("Failed to accept connection:", err)
continue
}
go func() {
for {
if agg.IsShutdown() {
return
}
conn, err := repListener.Accept()
if err != nil {
log.Println("Failed to accept connection:", err)
continue
}

go handleConnection(agg, conn)
}
go handleConnection(agg, conn)
}
}()
}

func handleConnection(agg *Aggregator, conn net.Conn) {
Expand Down
9 changes: 6 additions & 3 deletions aggregator/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ func (agg *Aggregator) startRpcServer(ctx context.Context) error {
agg.logger.Info("start grpc server",
"address", lis.Addr(),
)
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}

go func() {
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}()
return nil
}
Loading