On Sep 5, 1:32 pm, bill walton <[email protected]> wrote:
> Hi Phil,
>
> On Sat, 2009-09-05 at 04:41 -0700, phil wrote:
> > I have what I thought would be a simple thing - we use backgroundrb to
> > watch a directory and process new files. We want to make sure that the
> > worker is running. I thought I could have a schedule that started the
> > worker every 5 minutes to make sure, but, it loads a new one each time
> > (not surprising).
> > Is there a way to make sure that there is one (and only one) of these
> > workers running at all times?
>
> You'll probably have better luck with this on the backgroundrb list.
>
> http://backgroundrb.rubyforge.org/community/
>
> HTH,
> Bill


BackgrounDRb or no, creating a  file containing the process's PID, and
verifying that each time the process is started is the typical unixy
way to do this.  How I do it:

  def self.is_running?
    if File.exists? pidfile
      begin
        Process.kill 0, pid
        return true
      rescue Errno::EPERM
        puts "You don't own this process."
        return true
      rescue Errno::ESRCH #pid doesn't exist anymore
        delete_pidfile
      end
    end
    false
  end

  def self.delete_pidfile
    File.delete pidfile
  rescue
  end

  def self.pid
    File.read(pidfile).chomp.to_i rescue nil
  end

  def self.pidfile
    "path/to/background_process.pid"
  end


And of course just create the the appropriate file writing Process.pid
to it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to