generated from sergeyWh1te/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Split up feeder, forwarder to independent bin applications (#32)
Signed-off-by: sergeyWh1te <[email protected]>
- Loading branch information
1 parent
1ecd683
commit 534ef25
Showing
7 changed files
with
125 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/go-chi/chi/v5" | ||
"github.com/nats-io/nats.go/jetstream" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"golang.org/x/sync/errgroup" | ||
|
||
"github.com/lidofinance/finding-forwarder/internal/app/feeder" | ||
"github.com/lidofinance/finding-forwarder/internal/app/server" | ||
"github.com/lidofinance/finding-forwarder/internal/connectors/logger" | ||
"github.com/lidofinance/finding-forwarder/internal/connectors/metrics" | ||
nc "github.com/lidofinance/finding-forwarder/internal/connectors/nats" | ||
"github.com/lidofinance/finding-forwarder/internal/env" | ||
) | ||
|
||
func main() { | ||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL) | ||
defer stop() | ||
g, gCtx := errgroup.WithContext(ctx) | ||
|
||
cfg, envErr := env.Read("") | ||
if envErr != nil { | ||
fmt.Println("Read env error:", envErr.Error()) | ||
return | ||
} | ||
|
||
log := logger.New(&cfg.AppConfig) | ||
|
||
natsClient, natsErr := nc.New(&cfg.AppConfig, log) | ||
if natsErr != nil { | ||
log.Error(fmt.Sprintf(`Could not connect to nats error: %v`, natsErr)) | ||
return | ||
} | ||
defer natsClient.Close() | ||
log.Info("Nats connected") | ||
|
||
js, jetStreamErr := jetstream.New(natsClient) | ||
if jetStreamErr != nil { | ||
fmt.Println("Could not connect to jetStream error:", jetStreamErr.Error()) | ||
return | ||
} | ||
log.Info("Nats jetStream connected") | ||
|
||
r := chi.NewRouter() | ||
metricsStore := metrics.New(prometheus.NewRegistry(), cfg.AppConfig.MetricsPrefix, cfg.AppConfig.Name, cfg.AppConfig.Env) | ||
|
||
services := server.NewServices(&cfg.AppConfig, metricsStore) | ||
app := server.New(&cfg.AppConfig, log, metricsStore, js, natsClient) | ||
|
||
app.Metrics.BuildInfo.Inc() | ||
|
||
feederWrk := feeder.New(log, services.ChainSrv, js, metricsStore, cfg.AppConfig.BlockTopic) | ||
feederWrk.Run(gCtx, g) | ||
|
||
app.RegisterWorkerRoutes(r) | ||
app.RegisterInfraRoutes(r) | ||
app.RunHTTPServer(gCtx, g, cfg.AppConfig.Port, r) | ||
|
||
log.Info(fmt.Sprintf(`Started %s feeder`, cfg.AppConfig.Name)) | ||
|
||
if err := g.Wait(); err != nil { | ||
log.Error(err.Error()) | ||
} | ||
|
||
fmt.Println(`Main done`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
internal/app/worker/worker.go → internal/app/forwarder/forwarder.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package worker | ||
package forwarder | ||
|
||
import ( | ||
"bytes" | ||
|