Skip to content

Commit

Permalink
feat: set fail strategies to system
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Nov 22, 2022
1 parent 6698596 commit 329f72a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions app/system/bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package system

import (
"time"

"okp4/nemeton-leaderboard/app/actor/event"
"okp4/nemeton-leaderboard/app/actor/graphql"

Expand All @@ -18,9 +20,18 @@ func Bootstrap(listenAddr, mongoURI, dbName string) *App {
if _, ok := ctx.Message().(*actor.Started); ok {
boot(ctx, listenAddr, mongoURI, dbName)
}
})
}).Configure(actor.WithSupervisor(actor.NewAllForOneStrategy(
3, time.Second, func(reason interface{}) actor.Directive {
return actor.EscalateDirective
},
)))

ctx := actor.NewActorSystem().Root
ctx := actor.NewActorSystem().Root.
WithGuardian(actor.NewOneForOneStrategy(
1, time.Second, func(reason interface{}) actor.Directive {
return actor.EscalateDirective
},
))
initPID, err := ctx.SpawnNamed(initProps, "init")
if err != nil {
log.Panic().Err(err).Msg("❌ Could not create init actor")
Expand All @@ -44,10 +55,10 @@ func boot(ctx actor.Context, listenAddr, mongoURI, dbName string) {
log.Panic().Err(err).Str("actor", "graphql").Msg("❌Could not create actor")
}

eventPublisherProps := actor.PropsFromProducer(func() actor.Actor {
return event.NewPublisherActor(mongoURI, dbName)
eventStoreProps := actor.PropsFromProducer(func() actor.Actor {
return event.NewEventStoreActor(mongoURI, dbName)
})
if _, err := ctx.SpawnNamed(eventPublisherProps, "event-store"); err != nil {
log.Panic().Err(err).Str("actor", "event-publish").Msg("❌Could not create actor")
if _, err := ctx.SpawnNamed(eventStoreProps, "event-store"); err != nil {
log.Panic().Err(err).Str("actor", "event-store").Msg("❌Could not create actor")
}
}

0 comments on commit 329f72a

Please sign in to comment.