Skip to content

Commit

Permalink
feat(event): add store in actor
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Nov 18, 2022
1 parent 492ce4d commit c317273
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
25 changes: 0 additions & 25 deletions app/actor/event/store/actor..go

This file was deleted.

42 changes: 42 additions & 0 deletions app/actor/event/store/actor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package store

import (
"context"
"time"

"okp4/nemeton-leaderboard/app/event"

"github.com/asynkron/protoactor-go/actor"
"github.com/rs/zerolog/log"
)

type Actor struct {
mongoURI string
dbName string
eventStore *event.Store
}

func NewActor(mongoURI, dbName string) *Actor {
return &Actor{
mongoURI: mongoURI,
dbName: dbName,
}
}

func (a *Actor) Receive(ctx actor.Context) {
switch ctx.Message().(type) {
case *actor.Started:
a.handleStart()
}
}

func (a *Actor) handleStart() {
ctx, cancelFn := context.WithTimeout(context.Background(), time.Second)
defer cancelFn()

store, err := event.NewStore(ctx, a.mongoURI, a.dbName)
if err != nil {
log.Fatal().Err(err).Str("uri", a.mongoURI).Str("db", a.dbName).Msg("❌ Couldn't create event store")
}
a.eventStore = store
}

0 comments on commit c317273

Please sign in to comment.