Reputation: 777
I'm running a ruby program for a personal project, and because it takes around 20 hours to finish the execution I want to "save the state" of the program every hour or so, in case there is power outage in my building.
I want to be able to restart the execution using the last "saved state" of the program. But I don't know if there is tool for doing that or if have to hard code the entire thing my self.
Upvotes: 1
Views: 157
Reputation: 576
(Comments into an answer.)
You'll probably want to use Marshal[1]
. To save state, you dump()
, and to restore state you either load()
or restore()
. The details of the process are going to strongly depend on the way the objects are interconnected, and the amount of data you are saving. If the data are small enough, you can even use JSON, and forgo Marshal
.
You may have to experiment with the best choice for how to dump()/load()
your data, because if you have one over-arching object loading all of that data into memory can really bog you down (even with an enormous amount of memory available to you). You may instead need to break that monolith into many smaller objects that are individually marshalled, and then marshal their container.
Upvotes: 1