Step 1, 2 and 3 need to be done in sequence/synchronous which is OK because preStart runs asynchronously.
On Friday, February 5, 2016 at 4:47:22 PM UTC, Guido Medina wrote: > > Actor's A preStart does the following: > > 1. Load stuff from DB - *might fail and restart actor but is OK.* > 2. Do the task assigned to itself and save state - *might fail and > restart actor but is OK, **TODO:* how to handle failure of saving > state. > 3. For each subtask create an actor if any, otherwise poison itself > and notify its parent (I won't explain a stop condition for this) > > At step 2 is OK to restart because each actor is a unit of work that > either finishes successfully or fails completely, also assuming each unit > of work is idempotent (commit or roll back) > > What messages will get onReceive()? > > 1. SubTaskDone: Decrease counter, if counter is zero, notify my parent > and poison myself. > 2. PoisonPill: .... > > Guido. > > On Friday, February 5, 2016 at 4:34:59 PM UTC, Paul Cleary wrote: >> >> re: "The mechanism is a bit tricky", thanks goodness it isn't just me ;) >> >> Say I have a *JobSupervisorActor* that really manages work. He might >> get a message *StartJob(job)* for example. Handling might look like: >> 1. Save the job in the db >> 2. When job is saved successfully, spawn a *JobActor* child to start >> processing it >> >> The *JobActor* might do this: >> 1. preStart, load the job (and its sub-tasks) from db >> 2. For each task, start processing it >> 3. When a task completes, then save the state of the job in the database >> 4. When all tasks complete, then save the state of the job to mark it as >> done >> 5. Kill ourself >> >> What we are discussing is, what happens if the *JobActor* cannot save >> its state? >> >> If the *JobActor* throws an exception, he will be *re-started* by the >> *JobSupervisor* (his parent). >> >> We really want the *JobActor* to *continue* from the last known state of >> the job. >> >> You've been great, this is a very helpful dialog, also good for this user >> group in case someone else has the same conundrum in the future :) >> >> On Friday, February 5, 2016 at 11:18:50 AM UTC-5, Guido Medina wrote: >>> >>> The mechanism is a bit tricky. the trick is to use preStart() to do that >>> Job unit of work and the 1st message to process sub-task explained in >>> details: >>> >>> - Supervisor loads Job A which has a definition like how many times >>> should retry, how long to backoff, etc. >>> - Supervisor spawn actor A, if preStart has something to do it does >>> it and then message itself with StartSubTasks. >>> - Actor A receives StartSubTasks messages, creates a counter = size >>> of subtasks: >>> - For each sub-task spawn actor, when actor finishes sends message >>> to parent saying done and decrement counter, when counter is zero >>> poisonpill self. >>> >>> What I haven't figured out is how to write state of subtask and failure >>> for that for that pattern is a start, btw you don't need to stash, use >>> preStart for task and onReceive for sub-tasks. >>> >> -- >>>>>>>>>> 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.
