If you're running under a Unix-like system, then you can do something as
simple as this:
File.open("/tmp/mylock","w") do |f|
raise "Already running" unless f.flock(File::LOCK_EX | File::LOCK_NB)
... rest of code
end
Might even be able to combine the open and lock using IO.sysopen, I
haven't dug into that. Only works if all processes are on the same
machine of course.
However I don't think it's necessary for your job here:
> 1) pull images off a CF card on my laptop
> 2) move the images to a server
> 3) rename the images on the server according to the EXIF info
All your script needs to do is to 'grab' each file by renaming it using
File.rename, e.g. File.rename(fn, "#{fn}.working"). If this is
successful then it can be sure it has the file. If it fails, then it
means some other program grabbed the file first, so it can skip. However
if your script is aborted midway through it may leave some files in this
grabbed state, so they would need renaming back again manually.
Another option is to forget cron, and just start the program in the
background; it processes whatever files it can, sleeps for 300 seconds,
and then loops around. This will consume RAM on your machine while the
process sleeps though.
--
Posted via http://www.ruby-forum.com/.