How to write a reliable endless process?

I asked another question about browsing directories, which was answered, but the other half of the question is how best to create an endless process, in ruby, for this. Here are the requirements:

  • run forever
  • can be controlled (i.e. know up or down)
  • is there a way to restart it and provide it (God?)
  • start / stop using Capistrano (it would be nice!)

We looked at BackgroundRb, but it seems a bit outdated and, to be honest, unreliable! We watched DelayedJob, but it seems like one job (because endless work seems to block any other work from doing, because jobs are run sequentially).

We are launching a bunch of Ubuntu servers that shape our environment.

Any ideas?

+8
ruby ruby-on-rails
source share
4 answers

I have an event loop that processes some nginx log files and puts them in MongoDB. The log eater scripts work with ruby ​​daemons. http://daemons.rubyforge.org/

I found it much more reliable than god. It also tracks and restarts your script if it dies. If you want to be notified that the runner is dying, you can use monit to do this.

Here is my demon runner script:

#!/usr/bin/env ruby require 'rubygems' require 'bundler' Bundler.require(:default) Bundler.setup(:default) options = { :app_name => "log_eater", :dir_mode => :system, :multiple => true, :backtrace => true, :monitor => true } Daemons.run(File.join(File.dirname(__FILE__), 'log_eater.rb'), options) 

It works for months without leakage or no problem. God had problems with leaks and death. Capistrano can restart this by restarting your script run.

Here is an excerpt from mine for gentoo linux

 start() { ebegin "Starting log-eater" cd /ruby/STABLE/quickanalytics `scripts/log_eater_runner.rb start -- /usr/logs/nginx.log` eend $? "Failed to start log-eater" } 

- after the start command for any arguments that you want to pass to the script.

+3
source share

I would probably look at the daemon-kit . Not sure if it meets all your requirements:

https://github.com/kennethkalmer/daemon-kit

0
source share

See Paul Dix's book Service Oriented Design with Ruby and Rails . Also see Sinatra .

0
source share

In your case, I would use Resque. It seems to satisfy your requirements. I believe that it comes with sample scripts for capistrano to manage workers. Monitoring workers with God is a little trickier, but it comes with a web console so you can see what your employees are doing. There are a ton of plugins for it too, to satisfy any needs you may have.

https://github.com/defunkt/resque

0
source share

All Articles