From: James Gray Date: 2009-05-11T07:31:40+09:00 Subject: Re: Communicate with a daemon On May 10, 2009, at 4:22 PM, Paul A. wrote: > After daemonize a Ruby process (thanks Ruby version 1.9), it is > possible > to communicate with on the same machine by using socket on > localhost. Do > you know some other methods instead of socket? Sure. In I daemon I've been working on, I just use SQLite as a queue for messages. I use the Amalgalite extension, which is terrific and works well on Ruby 1.9. When you're going to write to the queue, make sure to grab an "exclusive" lock (via the "transaction" SQL command). When reading, grab an "immediate" lock first. Set a busy handler through Amalgalite that retries for a reasonable time (I use 60 seconds) to grab locks. Add some error handling code for if the lock wait does eventually timeout, but that shouldn't happen under normal operations. About the only challenges I ran into were deleting data from the queue. Deleting counts as a write, so grab an "exclusive" lock. That was easy of course. The downside is that the SQLite database needs to have the "vacuum" command run on it every so often to reclaim wasted disk space. You can't be holding a lock when you do that though. Thus I locked on an external source about once a day, and vacuumed the database. If it's just a simple queue you need (with no long term storage), you could also just nuke the file and rebuild it periodically. Anyway, I hope that gives you some fresh ideas. James Edward Gray II