How to keep Akka running all the time in Play 2.3

291 views Asked by At

I am using akka as a scheduler in a website written with Play framework 2.3. I kept the server running by using activator run in dev environment.

And when I changed some files and tried to visit my website, the Play server will compile these changed files and reload the server, which caused the Akka scheduler shut down and restart. Then all my scheduled tasks cannot be executed in correct sequence and caused a logical mess.

I want to ask if I can find a way to let the Akka scheduler keep running all the time until I send a signal to it to let it reload?

And can I do it in both dev env and prod env?

1

There are 1 answers

0
Michał Płachta On BEST ANSWER

The problem you are facing goes beyond development changes in files. You want your actor to be able to hold the state no matter what happens to the play application (maybe it failed for different reason?).

Basically you want your scheduling actor to be persistent. It is very easy to transform your actor into persistent one. You need to extend PersistentActor and replace your receive with receiveCommand and receiveRecover.

The state is saved to the journal file by default but you can choose a different persistence layer.

You can find more on that in Akka documentation.