9

I want to save my Pharo image every hour on the hour automatically.

How would you make this automatic within the image?

I've seen the Pier project do this. But I'm not sure how they do it.

TIA

unom
  • 11,438
  • 4
  • 34
  • 54
elviejo79
  • 4,592
  • 2
  • 32
  • 35

3 Answers3

5

Result of a discussion on the mailing list, with some icing around to run it only hourly:

[[self blockUI.
  self doUpdate.
  SmalltalkImage current snapshot: true andQuit: false.
  self unblockUI.
  (Delay forDuration: (Duration hours: 1)) wait] repeat] fork
nes1983
  • 15,209
  • 4
  • 44
  • 64
  • Farther down [that same thread](http://lists.gforge.inria.fr/pipermail/pharo-project/2010-July/029851.html) there's also a mention of `UnixProcess saveImageInBackgroundNicely` from *OSProcess* that can save an image using a background Unix process. You may prefer using this if you don't want the image to block every hour. – Alex Jasmin Jan 11 '11 at 20:03
  • Hmm. I can't find a method named saveImageInBackgroundNicely in Pharo 1.1.1. Neither a class UnixProcess. I wonder what happened there. – nes1983 Jan 11 '11 at 22:00
  • That class is from [OSProcess](http://www.squeaksource.com/OSProcess.html) which is not included in the base Pharo. – Alex Jasmin Jan 12 '11 at 03:13
  • Hi @nes1983 Thank you this saves the image. How do you make it save every hour? – elviejo79 Jan 12 '11 at 07:12
  • Note that Timespan has a method called "every:do:", and while the name is intriguing, it doesn't do at all what you expect. It doesn't wait at all. – nes1983 Jan 12 '11 at 10:00
5

There is the Scheduler project on SqueakSource that looks like cron for Smalltalk. From the overview:

"Start a new task scheduler and keep it around"
scheduler := TaskScheduler new.
scheduler start.
"Let's save the image every hour"
scheduler
   do: [Smalltalk snapshot: true andQuit: false]
   every: 60 minutes.

You could combine that with the blocking code or OSProcess's saveImageInBackgroundNicely mentioned above and have a nice easy solution.

Sean DeNigris
  • 6,306
  • 1
  • 31
  • 37
  • Thank you. Scheduler works pretty well. I just used: do: [SmalltalkImage current snapshot: true andQuit: false.] And also made smalltalk Run as Adiministrator so that it could save the file. – elviejo79 Jan 13 '11 at 23:47
1

You can do it and it might work just fine.

But I wouldn't do it.

Not fot persistence in production.

Why?

Because images are like your session in your laptop. Saving your image is like putting your laptop to sleep: it persists everything.

And in the long run, some state will have some unexplainable shit that can complicate something and you will need to do a hard reboot.

It doesn't help to try to be perfectionist about it (or maybe it does but is certainly not economic). It will just happen and rebooting your laptop is the cheap solution to have fresh state. But that for your smalltalk app may not be that cheap.

A hard reboot in smalltalk will mean that you have to take a fresh image and load again all your code (it can be automated but experience tells that could be time consuming).

Sebastian Sastre
  • 2,034
  • 20
  • 21
  • +1 for bringing this view but I don't agree. Image based persistence can be used successfully. I think even Dabble DB relied on it (using one image per customer). It can be harder to identify certain problems in a complex object graph than a schema based database and Squeak itself can only handle so much data but it's all about trade-offs. – Alex Jasmin Feb 10 '11 at 18:07
  • 1
    Also, to make reasonable persistence in images, you need to be flexible about transactions. If the server (or the VM) goes down for any reason before a save it **will** hurt. Not all applications can allow the luxury of not being ACID. – Sebastian Sastre Apr 15 '11 at 19:36