How to save a Pharo image automatically every hour?
Asked Answered
F

3

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

Fennel answered 11/1, 2011 at 8:20 Comment(0)
D
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.

Date answered 12/1, 2011 at 18:36 Comment(1)
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.Fennel
R
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
Ride answered 11/1, 2011 at 11:16 Comment(5)
Farther down that same thread 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.Oesophagus
Hmm. I can't find a method named saveImageInBackgroundNicely in Pharo 1.1.1. Neither a class UnixProcess. I wonder what happened there.Ride
That class is from OSProcess which is not included in the base Pharo.Oesophagus
Hi @Ride Thank you this saves the image. How do you make it save every hour?Fennel
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.Ride
D
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.

Date answered 12/1, 2011 at 18:36 Comment(1)
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.Fennel
H
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).

Hescock answered 17/1, 2011 at 20:11 Comment(2)
+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.Oesophagus
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.Hescock

© 2022 - 2024 — McMap. All rights reserved.