Thanks, yea, I like the Backoff Supervisor, very handy.  I tinkered with 
that already for handling this kind of scenario.

The next challenge that follows here is what to do when you are maintaining 
state in a database.

Imagine you have a long running process / job that you are monitoring.

You might have something like `Job -- 1 to many --> Task`

As each Task is completed, the Job will update its state in the db (or the 
Task can do it, doesn't matter for discussion purposes).

I feel like there are two models here:

1. Pass the Job to the actor and let it run
2. Pass the Job id to the actor, and let it load its state from the 
database to allow it to recover

Here is what I am thinking:

class JobActor(job: Job) extends Actor {
  
  def receive = {
    case Process => 
      // lets assume the process method starts a child actor processing 
results, they will let us know when they are done
      job.tasks.foreach(process)

    case Task.Complete(task) =>
      db.save(job.complete(task)) pipeTo self

    case akka.status.Failure(e) => throw e
  }

  override def preStart() = {
    self ! Process
  }  
}



In this example, we assume that the supervisor will restart.  Restarting 
from what I understand will pass in the Props, which would be the *original* 
job 
state.  Which kinda stinks be cause *all* tasks will be restarted.

What we really want is to (as best we can), restart from the *last know 
state of the job*

This is the problem I am trying to tackle.  

In the second solution, it could look something like the following:

class JobActor(job: Job) extends Actor with Stash {

  def receive = loading
 
  def loading: Receive = {
    case Loaded(job) =>
      job.tasks.foreach(process)
      unstashAll()
      context.become(running, false)

    case akka.status.Failure(e) => throw e
  }

  def running = {
    case Task.Complete(task) =>
      db.save(job.complete(task)) pipeTo self

    case akka.status.Failure(e) => throw e
  }

  override def preStart() = {
    db.load(jobId).map(Loaded) pipeTo self
  }  
}



In this solution, we always load the current state from the database when 
this actor loads.  

I am curious from a design perspective if this makes sense.

Sorry for the long question, just sorting through the best way to handle 
database failure when managing state across long running processes.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to