Skip to content

Instantly share code, notes, and snippets.

@thbar
Created February 13, 2011 17:46
Show Gist options
  • Save thbar/824880 to your computer and use it in GitHub Desktop.
Save thbar/824880 to your computer and use it in GitHub Desktop.
How to use a bundler group to define a reduced-memory consumption environment for your workers
# these gems won't be loaded by our Rakefile with WORKER_ENVIRONMENT enabled
gem 'rails', '3.0.3'
gem 'haml', '3.1.0.alpha.147'
# ...
# load these both for the app and the workers
group :default, :worker do
gem 'mongo', '1.1.5'
gem 'bson', '1.1.5'
gem 'bson_ext', '1.1.5'
gem 'mongomatic', '0.7.3'
gem 'i18n', '0.5.0'
gem 'configatron', '2.6.4'
gem 'resque', '1.10.0'
# careful, the next version apparently requires redis > 1.3
gem 'resque-scheduler', '1.9.6'
gem 'hoptoad_notifier', '2.4.2'
# ...
end
unless ENV['WORKER_ENVIRONMENT'] == '1'
require File.expand_path('../config/application', __FILE__)
MyApp::Application.load_tasks
else
require 'rubygems'
require 'bundler'
ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile', File.dirname(__FILE__))
Bundler.require(:worker)
end
require 'rake'
require 'resque/failure/multiple'
require 'resque/failure/redis'
require 'resque/failure/hoptoad'
require 'resque/tasks'
require 'resque_scheduler/tasks'
# note - resque:setup doesn't depend on :environment in this mode
task "resque:setup" do
# ...
Resque::Failure::Hoptoad.configure do |config|
config.api_key = 'xxxx'
end
# do this at the end to enable the multiple backend (last wins)
Resque::Failure::Multiple.configure do |config|
# keep Redis first
config.classes = [Resque::Failure::Redis, Resque::Failure::Hoptoad]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment