Browse files

added some examples

  • Loading branch information...
1 parent d5dcd19 commit a9e0f9a7ebe88e018e1f61fddb8928dcc8aec765 @nevans committed Jul 30, 2010
Showing with 74 additions and 5 deletions.
  1. +5 −5
  2. +8 −0 examples/Rakefile
  3. +26 −0 examples/rails-resque.rake
  4. +4 −0 examples/resque-pool.yml
  5. +31 −0 examples/
@@ -2,9 +2,9 @@ Resque Pool
Resque pool is a simple library for managing a pool of resque workers. Given a
-a config file (`resque-pool.yml` or `config/resque-pool.yml`) or a simple
-config hash, it will manage your workers for you, starting up the appropriate
-number of workers for each.
+a config file (`resque-pool.yml` or `config/resque-pool.yml`) or a config hash,
+it will manage your workers for you, starting up the appropriate number of
+workers for each.
@@ -13,8 +13,8 @@ Benefits
ruby with copy-on-write safe garbage collection, this could save you a lot of
memory when you are managing many workers.
* Simpler (less) config - If you are using monit or an init script to start up
- your workers, you can simply start up one pool, and it will manage your
- workers for you.
+ your workers, you can start up one pool, and it will manage your workers for
+ you.
* Faster startup - if you are starting many workers at once, you would normally
have them competing for CPU as they load their environments. Resque-pool can
load the environment once and almost instantaneously fork all of the workers.
@@ -0,0 +1,8 @@
+# If you have redis running on the standard port on localhost, then you can
+# test out resque-pool in the examples directory by running:
+# rake --trace resque:pool
+# And then you can poke and prod the various processes with signals and edit
+# the config file, etc.
+require 'resque/pool/tasks'
@@ -0,0 +1,26 @@
+require 'resque/pool/tasks'
+# this task will get called before resque:pool:setup
+# preload the rails environment in the pool master
+task "resque:setup" => :environment do
+ # generic worker setup, e.g. Hoptoad for failed jobs
+# preload the rails environment in the pool master
+task "resque:pool:setup" do
+ # it's better to use a config file, but you can also config here:
+ # Resque::Pool.config = {"foo" => 1, "bar" => 1}
+ # close any sockets or files in pool master
+ ActiveRecord::Base.connection.disconnect!
+ # and re-open them in the resque worker parent
+ Resque::Pool.after_prefork do |job|
+ ActiveRecord::Base.establish_connection
+ end
+ # you could also re-open them in the resque worker child, using
+ # Resque.after_fork, but that probably isn't necessary, and
+ # Resque::Pool.after_prefork should be faster, since it won't run
+ # for every single job.
@@ -0,0 +1,4 @@
+foo: 1
+bar: 2
+"foo,bar,baz": 4
@@ -0,0 +1,31 @@
+# This startup script takes one argument, the RAILS_ROOT, starts up
+# resque-pool with logfiles and a pidfile, and returns immediately
+# (resque-pool is backgrounded). It should be run as the appuser.
+# TODO: move all of the functionality of this file into the ruby script.
+# The following environment variables are set explicitly here to ensure that
+# they are set to exactly what I expect, no matter how the app is run.
+# Setting these here may not be necessary for your environment.
+export HOME=/home/appuser
+# Make sure we are using the correct rake with the correct ruby
+export PATH=/opt/ruby-enterprise-1.8.6-20090610/bin:/usr/local/bin:/usr/bin:/bin
+# There's probably no compelling need to split stdout and stderr into two
+# separate files. Most of the time, resque doesn't send anything to stderr
+# anyway.
+export RAILS_ENV=production
+#export VERBOSE=true
+#export VVERBOSE=true
+$RAKE --trace resque:pool >> $STDOUT_FILE 2>> $STDERR_FILE &
+echo $! > $PID_FILE

0 comments on commit a9e0f9a

Please sign in to comment.