Will delayed job work with Rails 4?
Currently, I am upgrading my application to Rails 4 and using
gem "delayed_job", :git => 'git://github.com/collectiveidea/delayed_job.git'
in gemfile.
when i run rake jobs:work i got error like this
Error while reserving job: undefined method reserve for
Delayed::Job:Class
any help on this?
add this gem 'delayed_job_active_record' line below gem "delayed_job" to your gem file like this,
gem "delayed_job", :git => 'git://github.com/collectiveidea/delayed_job.git'
gem 'delayed_job_active_record'
and do
bundle install
then try
bundle exec rake jobs:work
hope it will work.
Delayed job will work on rails 4. But the delayed_job folder inside the bin folder.
So, You can run delayed job by following command
bin/delayed_job start`
Related
UserMailer with delay method not working in rails 4. As mentioned below, this code doesn't works
def welcome_email
UserMailer.delay.welcome_email(self)
end
But when I use below code it works fine.
UserMailer.welcome_email(self).deliver
I have installed 2 gems, i.e
gem 'delayed_job'
gem 'delayed_job_active_record'
You need to pass ENV variables to your worker command.
Use this command in your command line:
rake jobs:work RAILS_ENV=development VARIABLE_1='' VARIABLE_2=''
I set up Capistrano to make the deploy of my app. I made it in steps, so first I set up the code deployment, so I commented all the roles but :app.
I'm using rvm and I had some problems with it. The biggest problem was an error that said /usr/bin/env: ruby: No such file or directory. I solved them using the gem capistrano/rvm and requiring it in the Capfile and adding the following line to the deploy.rb file:
set :default_env, { path: "/usr/local/rvm/gems/ruby-2.0.0-p247#global/bin:$PATH" }
Once the code deploying runned correctly I activated de :db role in order to perform migrations. I get the same error but I can't find the solution this time.
~$ cap production deploy:migrate
…
…
INFO [85d6241d] Running bundle exec rake db:migrate on 10.10.51.10
DEBUG [85d6241d] Command: cd [PROJECT_SRC]/current
&& ( PATH=/usr/local/rvm/gems/ruby-2.0.0-p247#global/bin:$PATH RAILS_ENV=production bundle exec rake db:migrate )
DEBUG [85d6241d] /usr/bin/env: ruby: No such file or directory
cap aborted!
This command runs correctly when I execute it directly in the shell.
Thank you in advance!
Finally it worked using gem 'rvm1-capistrano3', require: false. It seems the best option for my setup (Rails4.0.1, ruby-2.0.0-p247, capistrano3). It didn't require special configuration.
You can find it here.
Hope it helps someone!
I had similar problem and this gem helped me:
https://github.com/wayneeseguin/rvm-capistrano
If you are not using rvm, then the issue is usually you'll have to manually install bundler gem on the server.
gem install bundler
Have you tried offical capistrano gems? That helped me, maybe your use case is similiar.
Gemfile:
...
gem 'capistrano', '~> 3.2.0'
gem 'capistrano-rvm'
gem 'capistrano-rails'
...
Capfile:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
...
I have this configuration in my Gemfile:
group :test do
# ...
gem "shoulda-matchers", :git => "git://github.com/watu/shoulda-matchers.git", :branch => "do_not_load_minitest"
end
which works fine locally, but when I push to Heroku, when I try to run rake db:migrate, I get this error:
git://github.com/watu/shoulda-matchers.git (at do_not_load_minitest) is not checked out. Please run bundle install
Indeed I don't see it in the output of bundle install being run on Heroku, maybe because it's on the test group and Heroku is not installing the test group. But then, why is it complaining when I run rake db:migrate? should it run in staging env?
I tried switching to the http url and all I got is the same error with another URL:
https://github.com/watu/shoulda-matchers.git (at do_not_load_minitest) is not checked out. Please run bundle install
Moving the line outside the :test group workarounded the problem. What's the proper solution?
If you don't really need that gem (since it is in :test group), you can add this configuration to your app:
heroku config:add BUNDLE_WITHOUT="development:test" --app <your_app>
I have a rake task that looks like so (crontab):
cd /data/TheApp/current && bundle exec rake nightly_tasks[3]
--trace --silent 2>> /data/TheApp/shared/log/tasks_prod_errors.log
It all runs fine in test and dev, but on prod I get this error:
rake aborted!
no such file to load -- ruby-debug
/usr/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in
`require'
/usr/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in
`block (2 levels) in require'
OK so I check my gemfile and I have this:
group :development, :test do
gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :ruby
...
Production env should be ignoring that ruby-debug requirement. So I check my RAILS_ENV and it's correct:
$ echo $RAILS_ENV
production
On top of that the line that used to require ruby debug in this rake task is commented out. So to me it looks like there's no way bundle exec should be trying to load ruby-debug in prod. Is this maybe something to do with the gemfile.lock? There is an entry for ruby-debug19 in there. But why would my rake task be loading it in that case?
Also, running the command from the command line works fine. Confusing.
The rails environment and bundler groups are two completely different things. One doesn't know about the other although they use similar terms in your case
As a workaround, you can use bundle install --without development test in production to tell bundler to not install those groups. Alternatively, you can use something like this in your Gemfile:
unless ENV['RAILS_ENV'] == "production"
gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :ruby
end
That expects that you have the environment variable RAILS_ENV set. during your bundle install run as well as during your bundle exec run (i.e. always).
All you need to do is use the “debugger” gem for ruby 1.9.
gem install debugger
I am trying to use the gem delayed_job from https://github.com/collectiveidea/delayed_job.
I put gem 'delayed_job_active_record' in my Gemfile and did bundle install.
Then, I did:
rails generate delayed_job
rake db:migrate
I believe the migration was supposed to create a table delayed_jobs, but it did not.
What am I missing?
Thanks.
If you are using Rails 3+, you need the following two in your Gemfile:
gem 'delayed_job'
gem 'delayed_job_active_record'
Then change your generate to:
rails g delayed_job:active_record
rake db:migrate
Read more info here and here.