Skip to content

Commit

Permalink
Merge pull request #238 from okp4/feat/disable-block-sync
Browse files Browse the repository at this point in the history
feat(cmd): allow to disable block sync
  • Loading branch information
amimart committed Dec 15, 2023
2 parents 9178b9b + c3853a7 commit 12069b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 13 additions & 11 deletions app/system/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type App struct {
func Bootstrap(
listenAddr, mongoURI, dbName, grpcAddr, twitterToken, twitterAccount string,
tls credentials.TransportCredentials,
accessToken *string,
accessToken *string, noBlockSync bool,
) *App {
initProps := actor.PropsFromFunc(func(ctx actor.Context) {
if _, ok := ctx.Message().(*actor.Started); ok {
boot(ctx, listenAddr, mongoURI, dbName, grpcAddr, twitterToken, twitterAccount, tls, accessToken)
boot(ctx, listenAddr, mongoURI, dbName, grpcAddr, twitterToken, twitterAccount, tls, accessToken, noBlockSync)
}
})

Expand All @@ -47,7 +47,7 @@ func (app *App) Stop() error {

func boot(ctx actor.Context, listenAddr, mongoURI, dbName, grpcAddr, twitterToken, twitterAccount string,
tls credentials.TransportCredentials,
accessToken *string,
accessToken *string, noBlockSync bool,
) {
grpcClientProps := actor.PropsFromProducer(func() actor.Actor {
grpcClient, err := cosmos.NewGrpcClient(grpcAddr, tls)
Expand All @@ -72,15 +72,17 @@ func boot(ctx actor.Context, listenAddr, mongoURI, dbName, grpcAddr, twitterToke

startSubscriber(ctx, eventStorePID, mongoURI, dbName)

blockSync := actor.PropsFromProducer(func() actor.Actor {
sync, err := synchronization.NewActor(eventStorePID, grpcClientPID, mongoURI, dbName)
if err != nil {
log.Panic().Err(err).Msg("❌ Could not start block synchronisation actor")
if !noBlockSync {
blockSync := actor.PropsFromProducer(func() actor.Actor {
sync, err := synchronization.NewActor(eventStorePID, grpcClientPID, mongoURI, dbName)
if err != nil {
log.Panic().Err(err).Msg("❌ Could not start block synchronisation actor")
}
return sync
})
if _, err := ctx.SpawnNamed(blockSync, "blockSync"); err != nil {
log.Panic().Err(err).Msg("❌ Could not create block sync actor")
}
return sync
})
if _, err := ctx.SpawnNamed(blockSync, "blockSync"); err != nil {
log.Panic().Err(err).Msg("❌ Could not create block sync actor")
}

tweetProps := actor.PropsFromProducer(func() actor.Actor {
Expand Down
4 changes: 4 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
FlagTLSSkipVerify = "tls-skip-verify"
FlagTwitterToken = "twitter-token" // nolint:gosec
FlagTwitterAccount = "twitter-account"
FlagNoBlockSync = "no-block-sync"
)

var (
Expand All @@ -35,6 +36,7 @@ var (
twitterToken string
twitterAccount string
accessToken string
noBlockSync bool

startCmd = &cobra.Command{
Use: "start",
Expand All @@ -54,6 +56,7 @@ var (
twitterAccount,
getTransportCredentials(),
accessTokenOpt,
noBlockSync,
)

kill := make(chan os.Signal, 1)
Expand Down Expand Up @@ -90,6 +93,7 @@ func init() {
"access-token",
"",
"The required access token for authenticated operations, an empty value = no auth")
startCmd.PersistentFlags().BoolVar(&noBlockSync, FlagNoBlockSync, false, "Disable block synchronization")
}

func getTransportCredentials() credentials.TransportCredentials {
Expand Down

0 comments on commit 12069b8

Please sign in to comment.