Created
August 9, 2010 21:14
-
-
Save kshahkshah/516134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require File.join(File.dirname(__FILE__), '..', 'environment') # note: not the rails env, my own thing | |
setup_bundler | |
setup_resque # boots redis, boots resque, connects them | |
require 'daemons' | |
require 'yaml' | |
# this is insanity but it works | |
queue = ARGV.last.split("=")[1] | |
app_name = "resque_worker_#{queue}" | |
interval = 5 | |
options = { | |
:app_name => app_name, | |
:dir_mode => :normal, | |
:dir => MyService.log_directory, | |
:multiple => false, | |
:mode => :load, | |
:backtrace => true, | |
:monitor => false, | |
:log_output => true | |
} | |
Daemons.run_proc(app_name, options) do | |
setup_core_models # loads some AR models | |
require queue # requires the actual queue worker | |
Resque.before_first_fork do | |
ActiveRecord::Base.connection.disconnect! | |
end | |
Resque.after_fork do | |
config = YAML::load_file(active_record_configuration_path) | |
ActiveRecord::Base.establish_connection(config[RUN_ENV]) | |
end | |
worker = Resque::Worker.new(queue) | |
worker.verbose = true | |
worker.log "Starting resque worker pointed at the #{queue} queue!" | |
worker.work(interval) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment