Restoring the State for a Node
Our process graph nodes are supervised, which means that they will get restarted when they die after erroring—which is a handy thing. But there’s a gotcha. They will get reborn as new blank nodes with no previous state. Another process will be set up to take over from the old process.
Obviously, we would like to capture any state from the old process and forward it to the new process—rather like a baton handover in a relay race.
As we saw earlier in Agents, we can use an agent to maintain the process state at this handover point. The trick here will be to push any process state onto the agent at the process termination and to fetch that back at the process initiation.
It’s time to fill out those do_init/0 and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access