Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PersistentLifecycleEvent is not sent to the actor #72

Closed
pmbanka opened this issue Sep 21, 2017 · 3 comments
Closed

PersistentLifecycleEvent is not sent to the actor #72

pmbanka opened this issue Sep 21, 2017 · 3 comments
Labels

Comments

@pmbanka
Copy link
Contributor

pmbanka commented Sep 21, 2017

Persistent actors don't receive PersistentLifecycleEvent. They receive Akka.Persistence.RecoveryCompleted directly. This can be verified by running this script:

#r "../src/Akkling/bin/Debug/Akka.dll"
#r "../src/Akkling/bin/Debug/Hyperion.dll"
#r "../src/Akkling/bin/Debug/Newtonsoft.Json.dll"
#r "../src/Akkling/bin/Debug/FSharp.PowerPack.dll"
#r "../src/Akkling/bin/Debug/FSharp.PowerPack.Linq.dll"
#r "../src/Akkling/bin/Debug/Akkling.dll"
#r "../src/Akkling/bin/Debug/System.Collections.Immutable.dll"
#r "../src/Akkling.Persistence/bin/Debug/Google.Protobuf.dll"
#r "../src/Akkling.Persistence/bin/Debug/Akka.Persistence.dll"
#r "../src/Akkling.Persistence/bin/Debug/Akkling.Persistence.dll"

open System
open Akkling
open Akkling.Persistence

let system = System.create "persisting-sys" <| Configuration.defaultConfig()

type CounterChanged =
    { Delta : int }

type CounterCommand =
    | Inc
    | Dec
    | GetState

type CounterMessage =
    | Command of CounterCommand
    | Event of CounterChanged

let actor (mailbox:Eventsourced<_>) =
    let rec loop state =
        actor {
            let! (msg : obj) = mailbox.Receive()
            match msg with
            | :? CounterMessage as cm -> 
                match cm with
                | Event(changed) -> return! loop (state + changed.Delta)
                | Command(cmd) ->
                    match cmd with
                    | GetState ->
                        mailbox.Sender() <! state
                        return! loop state
                    | Inc -> return Persist <| box (Event { Delta = 1 })
                    | Dec -> return Persist <| box (Event { Delta = -1 })
            | :? LifecycleEvent as x -> printfn "Lifecycle %A" x; return! loop state
            | :? PersistentLifecycleEvent as x -> printfn "Persistence Lifecycle %A" x; return! loop state          
            | x -> printfn "Catch all %A" x; return! loop state
        }
    loop 0

let counter : IActorRef<CounterMessage> = spawn system "counter-1" <| propsPersist actor |> retype

which results with

Lifecycle PreStart
Catch all Akka.Persistence.RecoveryCompleted
@Horusiath Horusiath added the bug label Sep 21, 2017
Horusiath added a commit that referenced this issue Nov 26, 2017
@Horusiath
Copy link
Owner

I've made an example test, which confirms, that PersistenceLifecycleEvent (at least for success) is fired as it should.

@cotyar
Copy link
Contributor

cotyar commented Dec 9, 2017

Please ignore my previous messages (deleted now). Found the proper way of doing it in Wiki.

@pmbanka
Copy link
Contributor Author

pmbanka commented Dec 20, 2017

I can confirm that with latest Akkling, the above script returns

Lifecycle PreStart
Persistence Lifecycle ReplaySucceed
Catch all Akka.Persistence.RecoveryCompleted

so I guess this is fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants