-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: implement event-sourced (persistent) actor
- Loading branch information
Denys Fakhritdinov
committed
Nov 21, 2023
1 parent
a3140b3
commit b7ae06e
Showing
33 changed files
with
903 additions
and
552 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
8 changes: 0 additions & 8 deletions
8
...ersistence/src/main/scala/com/evolution/akkaeffect/eventsopircing/persistence/Event.scala
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
...rc/main/scala/com/evolution/akkaeffect/eventsopircing/persistence/EventSourcedStore.scala
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...sistence/src/main/scala/com/evolution/akkaeffect/eventsopircing/persistence/package.scala
This file was deleted.
Oops, something went wrong.
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
71 changes: 71 additions & 0 deletions
71
persistence-api/src/main/scala/com/evolutiongaming/akkaeffect/persistence/Append.scala
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,71 @@ | ||
package com.evolutiongaming.akkaeffect.persistence | ||
|
||
import cats.implicits._ | ||
import cats.{Applicative, FlatMap, Monad, ~>} | ||
import com.evolutiongaming.akkaeffect.Fail | ||
import com.evolutiongaming.catshelper.{Log, MeasureDuration, MonadThrowable} | ||
|
||
trait Append[F[_], -A] { | ||
|
||
/** | ||
* @param events to be saved, inner Nel[A] will be persisted atomically, outer Nel[_] is for batching | ||
* @return SeqNr of last event | ||
*/ | ||
def apply(events: Events[A]): F[F[SeqNr]] | ||
} | ||
|
||
object Append { | ||
|
||
def const[F[_], A](seqNr: F[F[SeqNr]]): Append[F, A] = { | ||
class Const | ||
new Const with Append[F, A] { | ||
def apply(events: Events[A]) = seqNr | ||
} | ||
} | ||
|
||
def empty[F[_]: Applicative, A]: Append[F, A] = | ||
const(SeqNr.Min.pure[F].pure[F]) | ||
|
||
implicit class AppendOps[F[_], A](val self: Append[F, A]) extends AnyVal { | ||
|
||
def mapK[G[_]: Applicative](f: F ~> G): Append[G, A] = { events => | ||
f(self(events)).map { a => | ||
f(a) | ||
} | ||
} | ||
|
||
def convert[B](f: B => F[A])(implicit F: Monad[F]): Append[F, B] = { | ||
events => | ||
{ | ||
for { | ||
events <- events.traverse(f) | ||
seqNr <- self(events) | ||
} yield seqNr | ||
} | ||
} | ||
|
||
def narrow[B <: A]: Append[F, B] = events => self(events) | ||
|
||
def withLogging1(log: Log[F])( | ||
implicit | ||
F: FlatMap[F], | ||
measureDuration: MeasureDuration[F] | ||
): Append[F, A] = events => { | ||
for { | ||
d <- MeasureDuration[F].start | ||
r <- self(events) | ||
} yield | ||
for { | ||
r <- r | ||
d <- d | ||
_ <- log.debug(s"append ${events.size} events in ${d.toMillis}ms") | ||
} yield r | ||
} | ||
|
||
def withFail(fail: Fail[F])(implicit F: MonadThrowable[F]): Append[F, A] = { | ||
events => | ||
fail.adapt(s"failed to append $events") { self(events) } | ||
} | ||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
persistence-api/src/main/scala/com/evolutiongaming/akkaeffect/persistence/Event.scala
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,8 @@ | ||
package com.evolutiongaming.akkaeffect.persistence | ||
|
||
trait Event[E] { | ||
|
||
def event: E | ||
def seqNr: SeqNr | ||
|
||
} |
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
Oops, something went wrong.