I'm running a Rails 3 app with delayed_job. The issue I've come across is that though the app is correctly adding jobs to the queue, they are never being processed.
My Class
class User < ActiveRecord::Base
after_create :send_welcome_email
private
def send_welcome_email
UserMailer.delay.welcome_email(self)
end
end
Inspecting things through the Rails console I can see that there are jobs in the queue. I can also see that there have been 0 attempts to perform the jobs. Spinning up a Heroku worker doesn't cause the jobs to be processed.
Any ideas?
Thanks!
Edit: Trying to clear the jobs queue as suggested below I ran rake jobs:clear and received the following error
rake aborted!
uninitialized constant Rake::DSL
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (requ
ired)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>
'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
/app/Rakefile:7:in `<top (required)>'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/ruby1.9.2/bin/rake:31:in `<main>'
In the end, the problem turned out to be a bug in Rake 0.9.0. As Rails depends on Rake, running bundle install after this release of Rake broke my delayed jobs.
The fix is to add gem 'rake', '0.8.7' to your gemfile.
More details can be found below...
DHH's tweet: http://twitter.com/dhh/status/71966528744071169
Discussion in rails_admin's issue tracker: https://github.com/sferik/rails_admin/issues/428
Two options for you:
These two gems watch delayed_jobs queue and automatically 'hires' background workers to process the thread:
Option 1: https://github.com/michelson/hirefire (This is what I am using because it supports mongoid)
Option 2: This branch of delayed_job developed by a heroku engineer has a similar autoscale feature: https://github.com/pedro/delayed_job/tree/autoscaling
Good luck
Are you running the delayed_job daemon in the same environment in which the application is running?
Try working the jobs manually using:
rake RAILS_ENV=development jobs:work
If you are running your app in production mode then you need to start delayed_job daemon as:
RAILS_ENV=production script/delayed_job start
This is kinda a long shot but make sure you are using the same Ruby version on Heroku as you are on your local machine. I had a problem with delayed jobs on Heroku before because of this.
Related
I'm using 'sunspot_rails', '~> 2.0.0.pre.120415' for Solr search in my rails app and deploy it on heroku (two separate application).
It's working fine on one application but throw error on other.
I have checked the heroku environment and found that -
one app is on cedar stack and ruby version is 1.9.2p290. (Working fine)
other one is on bamboo stack and ruby version is 1.9.2p180 (throw error)
So, Is this the ruby version problem or heroku stack problem ?
Ruby version on development environment is 1.9.2p290.
Error
$ heroku run rake sunspot:reindex
Running rake sunspot:reindex attached to terminal... up, run.8567
rake aborted!
uninitialized constant Sunspot::Adapters::Registry::Forwardable
/app/.bundle/gems/ruby/1.9.1/gems/sunspot-2.0.0.pre.120925/lib/sunspot/adapters.rb:310:in `<class:Registry>'
/app/.bundle/gems/ruby/1.9.1/gems/sunspot-2.0.0.pre.120925/lib/sunspot/adapters.rb:309:in `<module:Adapters>'
/app/.bundle/gems/ruby/1.9.1/gems/sunspot-2.0.0.pre.120925/lib/sunspot/adapters.rb:34:in `<module:Sunspot>'
/app/.bundle/gems/ruby/1.9.1/gems/sunspot-2.0.0.pre.120925/lib/sunspot/adapters.rb:1:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/sunspot-2.0.0.pre.120925/lib/sunspot.rb:18:in `block in <top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/sunspot-2.0.0.pre.120925/lib/sunspot.rb:15:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/sunspot-2.0.0.pre.120925/lib/sunspot.rb:15:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/sunspot_rails-2.0.0.pre.120925/lib/sunspot/rails.rb:1:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/sunspot_rails-2.0.0.pre.120925/lib/sunspot_rails.rb:6:in `<top (required)>'
/app/config/application.rb:7:in `<top (required)>'
/app/Rakefile:4:in `require'
/app/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
To be even more clear, at the top of adapters.rb (sunspot/lib/sunspot/adapters.rb), add the following line:
require 'forwardable'
module Sunspot
#
# Sunspot works by saving references to the primary key (or natural ID) of
I have found the solution.
Actually it's a environment problem on heroku.On local system the ruby version is ruby 1.9.2p290 and on heroku is ruby 1.9.2p180. Ruby 1.9.2p180 doesn't include 'Forwardable' module. So I just need to include 'Forwardable' module in my application.
I've never sent this one before. I'm configuring a new server with an existing application. Trying to run a migration and here's the output.
root#beta:/vol/opt/dev/capistrano/foo-alpha/releases/20120330233010# RAILS_ENV=production rake db:migrate --trace
rake aborted!
private method `gsub' called for nil:NilClass
/usr/local/rvm/gems/jruby-1.6.6#global/gems/bundler-1.1.3/lib/bundler/runtime.rb:77:in `require'
org/jruby/RubyArray.java:1614:in `each'
/usr/local/rvm/gems/jruby-1.6.6#global/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
/usr/local/rvm/gems/jruby-1.6.6#global/gems/bundler-1.1.3/lib/bundler.rb:119:in `require'
/vol/opt/dev/capistrano/foo-alpha/releases/20120330233010/config/application.rb:7:in `(root)'
org/jruby/RubyKernel.java:1027:in `require'
/usr/local/rvm/rubies/jruby-1.6.6/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
/vol/opt/dev/capistrano/foo-alpha/releases/20120330233010/config/application.rb:4:in `(root)'
org/jruby/RubyKernel.java:1052:in `load'
/vol/opt/dev/capistrano/foo-alpha/releases/20120330233010/Rakefile:25:in `load_rakefile'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/local/rvm/gems/jruby-1.6.6#foo/gems/rake-0.9.2.2/bin/rake:33:in `(root)'
org/jruby/RubyKernel.java:1052:in `load'
/usr/local/rvm/gems/jruby-1.6.6#foo/bin/rake:19:in `(root)'
Migrations on my local laptop and on an existing server are working fine. config/database.yml looks right. Database is up and running and I can connect to it. What is this?
I also just tested rails console and I'm also not able to get a console. Again a private method gsub called for nil:NilClass. It's somehow related to connecting to the database and I'm not sure how/why.
** UPDATE **
After adding some debug into runtime.rb, this is the exception that's being raised:
#<LoadError: no such file to load -- activerecord-jdbcmysql-adapter>
The messed up part is, it is installed:
# gem list |grep -i activerecord-jdbcmysql-adapter
activerecord-jdbcmysql-adapter (1.2.2)
Is this some kind of RVM or bundler bug?
** LAST UPDATE **
I installed Amazon Linux AMI (The other is running an Ubuntu) and cannot replicate this issue there.
This is a bug in bundler, it was reported for rvm-capistrano, please check your Gemfile and try removing / commenting some gems.
https://github.com/carlhuda/bundler/issues/1801
from my research, bundle exec is responsible for executing a command in the context of a bundle.
anyway, I don't quite understand yet for what it does differently for just the command rake db:migrate comparing with bundle exec rake db:migrate.
for example in my case, I executed the first command, and what I got was the following errors:
$ rake db:migrate
(in c:/rails/rails_projects/soccerweb)
rake aborted!
uninitialized constant Rake::DSL
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:8:in `<clas
s:TaskLib>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:6:in `<modu
le:Rake>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:3:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `requ
ire'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `require'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `<top (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `block in <class:TestUnitRailtie>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
call'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
block in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `b
lock in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `all'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `l
oad_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application.rb:103:
in `load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurabl
e.rb:30:in `method_missing'
c:/rails/rails_projects/soccerweb/Rakefile:7:in `<top (required)>'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
c:/Ruby192/bin/rake:31:in `<main>'
but when I used "bundle exec" preceding that "rake db:migrate" command, everything just worked for me gracefully!
anyone can shed some light on me?
bundle exec rake runs the version of rake which you've specified in your Gemfile. The default version of rake, the one which can be found in your $PATH, might be different than one executed by bundle exec rake.
The problem you've experienced has been covered in a separate question. Your bundle exec rake most probably runs rake 0.8.7 and rake from your $PATH is a newer version which is affected by this problem.
Quoting from man bundle exec:
bundle exec makes a number of changes to the shell environment, then executes the command you specify in full.
(...)
put the directory containing executables (like rails, rspec, rackup) for your bundle on $PATH
Bundler solves gem dependencies for you. You can find read their rationale page for an explanation about their approach.
I am following the rails tutorial at railstutorial.org
I'm in chapter 2 and tried to migrate the database using rake as per the instructions: "To proceed with the demo application, we first need to migrate the database using Rake (Box 2.1)":
$ rake db:migrate
This did not work and I received the following error:
C:\Users\USER1\rails_project\demo_app>rake db:migrate
(in C:/Users/USER1/rails_project/demo_app)
rake aborted!
uninitialized constant Rake::DSL
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `load'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
C:/Users/USER1/rails_project/demo_app/Rakefile:7:in `<top (required)>'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
C:/Ruby192/bin/rake:31:in `<main>'
How can I resolve this?
This is a problem with the new (just released) version of rake. You can solve it by downgrading rake to 0.8.7. It's the simpler solution for a tutorial. See Rake 0.9.0 'undefined method 'task' ' and answers to that question.
You might add rake 0.8.7 to your Gemfile, like:
gem 'rake', '0.8.7'
And in the terminal you should run with
bundle exec rake db:migrate
And you are ready to follow, i hope this will help you.
I know you would have solved this issue long back but just in case anyone needs to know Rake .9.0 breaks Rails and several other things, you need to either go back to previous version or update the latest one (11.1.2):
gem "rake", "11.1.2"
in your Gemfile.
And then just follow these commands:
$ bundle update rake
Then check the rake with:
$ bundle show rake
And it should show rake 11.1.2.
After this you can successfully run
$ bundle exec rake db:migrate
(PS: hope this helps someone :) )
I am attempting to deploy my app to heroku via a windows 7 machine.
I've made it as far as git push heroku master without running into any major issues but when I try to rake the migrations i get the following error
$ heroku rake db:migrate --trace
rake aborted!
No such file or directory - /disk1/tmp/13403_23723015091620/.bundle/gems/specifi
cations/activesupport-2.3.8.gemspec
/disk1/home/slugs/211056_9194ad5_13a9/mnt/.bundle/environment.rb:178:in `read'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/.bundle/environment.rb:178
/disk1/home/slugs/211056_9194ad5_13a9/mnt/.bundle/environment.rb:147:in `map'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/.bundle/environment.rb:147
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/../config/preinitializer.rb:3
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/boot.rb:28:in `load'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/boot.rb:28:in `preinitialize'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/boot.rb:10:in `boot!'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/boot.rb:129
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' /disk1/home/slugs/211056_9194ad5_13a9/mnt/Rakefile:4
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2383:in `load'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:238
3:in `raw_load_rakefile'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2017:in `load_rakefile'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2000:in `run'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/bin/rake:31
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19
(in /disk1/home/slugs/211056_9194ad5_13a9/mnt)
I should mention, though it could be determined from the above code, that I am using bundler. Perhaps it is due to this.
I'm at a total loss as to what this could mean. I came across this SO thread, but all the fixes it presented I had already tried and they didn't work. I am beginning to appreciate why rails deployment is derided so. Any suggestions?
Did you already take a look on Heroku's documentation about Bundler at http://docs.heroku.com/bundler ?
Are you sure that your Gemfile and Gemfile.lock files are added to your git repository?
I'm able to duplicate this problem:
http://github.com/heroku/heroku/issues#issue/30
The same Rails app will deploy via OS X.