Skip to content

Instantly share code, notes, and snippets.

@wallace
Created March 8, 2009 18:29
Show Gist options
  • Save wallace/75857 to your computer and use it in GitHub Desktop.
Save wallace/75857 to your computer and use it in GitHub Desktop.
#run on command line with 'god -c backgroundrb.god -D'
RAILS_ROOT = '/var/www/rails/rollbook/current'
#load required rails and backgroundrb files
require File.dirname(__FILE__) + '/../boot'
require File.dirname(__FILE__) + '/../environment'
require 'erb'
$LOAD_PATH << "#{RAILS_ROOT}/vendor/plugins/backgroundrb/lib"
require "#{RAILS_ROOT}/vendor/plugins/backgroundrb/lib/backgroundrb.rb"
#create custom condition for checking that QueryProcessingWorker is running
MiddleMan = BackgrounDRb::ClusterConnection.new
module God
module Conditions
class Backgroundrb < PollCondition
def initialize; super; end
def valid?; true; end
def test
begin
queue_worker = MiddleMan.all_worker_info.values.flatten.select { |w| :queue_processing_worker == w[:worker] }
queue_worker.empty?
rescue #if all_worker_info raises exception, then bdrb isn't running and we were unable to connect
true
end
end
end
end
end
God.watch do |w|
w.name = 'backgroundrb'
w.interval = 1.minute
w.restart = "cd #{RAILS_ROOT} && #{RAILS_ROOT}/script/backgroundrb -e production stop && #{RAILS_ROOT}/script/backgroundrb -e production start"
w.stop = "cd #{RAILS_ROOT} && #{RAILS_ROOT}/script/backgroundrb -e production stop"
w.start = "cd #{RAILS_ROOT} && #{RAILS_ROOT}/script/backgroundrb -e production start"
w.grace = 1.minute
w.pid_file = "#{RAILS_ROOT}/tmp/pids/backgroundrb_11000.pid"
w.start_if do |start|
start.condition(:process_running) do |c|
c.running = false
end
end
w.restart_if do |restart|
restart.condition(:backgroundrb) do |c|
#just restart it
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment