After installing the Resque gem and running a worker my app now produces an asset pipeline error:
Sass:SyntaxError: File to import not found or unreadable
I created a fresh branch and narrowed the problem down to running the Resque worker. I’ve only changed three files. Here are the steps to reproduce:
1) Add the Resque gem to Gemfile:
gem 'resque'
2) Create a Resque rake task:
# lib/resque.rake
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
3) Add a worker to the Procfile:
web: bundle exec rails server -p $PORT thin
worker: bundle exec rake resque:work
I have a feeling that the problem is that the worker is trying to load all my assets. Which I don’t want because its just a background process. I’m not even running the Resque front end so the problem is unrelated to that.
The culprit was actually in my Resque initializer:
Heroku runs assets:precompile during slug compilation. During the precompile the environment is loaded, but Heroku does not pass in the ENV vars. The URI parse line was failing due to
being nil. This caused the assets:precompile rake task to fail.
The solution is to add:
to your application.rb file.
This is available as of Rails 3.1.1 and when set to false the environment will no longer be loaded when compiling the assets. This is a safe choice most of the times.
Thanks Neil for pointing me in the right direction.