Reputation: 1416
I am having a bit of difficulty with ActiveJob in Rails 4.2 and Resque.
I've installed redis and I've added resque and resque-scheduler to my Gemfile.
I've created a test job - it is just the generated file
rails g job test
but I keep getting errors about ActiveJob not defined
NameError: uninitialized constant ActiveJob
or missing method when I switch the adapter like this
config.active_job.queue_adapter = :resque
I get this error
/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0.beta1/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `active_job' for #<Rails::Application::Configuration:0x007f97ba98a5b8> (NoMethodError)
I've even looked at the source code but I have no idea. It is just calling super.
https://github.com/rails/rails/blob/master/railties/lib/rails/railtie/configuration.rb#L95
What I am missing? Why doesn't the queue adapter work? Does anyone know how to fix this?
Upvotes: 3
Views: 3579
Reputation: 5691
Add them the Gemfile with gem 'resque' and gem 'resque-scheduler' and bundle install. We'll also need to create a Resque configuration file:
#config/initializers/resque.rb
Resque.redis = Redis.new(:host => "localhost", :port => 6379)
We'll also require the Resque and Resque Scheduler rake tasks, so we can start our workers and scheduler with rake: #lib/tasks/resque.rake
require 'resque/tasks'
require 'resque/scheduler/tasks'
namespace :resque do
task :setup do
require 'resque'
require 'resque-scheduler'
end
end
We can now start a worker with QUEUE=* rake environment resque:work
. If everything's working right, we should be able to see it in the Resque console. Run resque-web
and visit http://0.0.0.0:5678/overview.
All we really need to do is configure it to use the Resque adapter.
#config/initializers/active_job.rb
ActiveJob::Base.queue_adapter = :resque
Now adding Jobs and enquing them should work as expected.
Also try updating rails gem if you see undefined ActiveJob
.
Upvotes: 2
Reputation: 1416
I turns out that I had selected which frameworks I was using.
# config/application.rb
require "active_model/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
The way to fix it, is to add the Active Job framework in the application.rb file.
require "active_job/railtie"
Or to load all of Rails
require 'rails/all'
This seems to be working now.
Upvotes: 6