uninitialized constant Delayed::Job

风格不统一 提交于 2020-01-23 04:21:48

问题


I've added the delayed_job gem to my gemfile and installed correctly but when I try to run the following line:

Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc

I get the error 'uninitialized constant Delayed::Job'

Can somebody explain what i need to do here? I've tried running 'rake jobs:work' beforehand but it also returns the 'uninitialized constant Delayed::Job' error. Additionally, I've added "require 'delayed_job'" to the file (application.rb) without much luck.


回答1:


Did you follow the installation instructions on the README file? https://github.com/collectiveidea/delayed_job

Add this to your gemfile:

gem 'delayed_job_active_record'

and then run this at the console:

$ rails generate delayed_job:active_record
$ rake db:migrate

You need to create the delayed jobs table in the database (this assumes you're using active record).

For Rails 3, all you need to do is include it in the gemfile, run that code above to create the table and migrate the database, then restart your server and go!




回答2:


If you've upgraded to delayed_job version >=3 you'll need to add this (presuming you're using ActiveRecord):

# Gemfile
gem 'delayed_job_active_record'



回答3:


I'm using delayed job within an engine (so the gem is specified in a .gemspec rather than Gemfile) and was getting the same error. I found that I could solve the problem by using:

require 'delayed_job_active_record'  # fixes problem

rather than

require 'delayed_job'                # doesn't



回答4:


Just in case, if this is still unanswered, check the below link

http://www.pipetodevnull.com/past/2010/4/14/uninitialized_constant_delayedjob/

edit: Alternative, just upgrade to the latest version - 2.1




回答5:


i was struggling a while back with the same problem. i was following ryan bates screencast on delayed_job and got the same error 'uninitialized constant Delayed::Job'. In the screencast ryan creates a file called mailing_job.rb(located under lib folder) with the delayed_job perform method inside, which allows you to use the enqueue method. After doing some research i found that rails 3 does not automatically load the lib folder files into your app.(not entirely sure)

Try this
In your controller where you use this:

"Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc" 

Try to require the file like this.

require 'mailing_job'
class AssetsController < ApplicationController
    def some_method
        Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc
    end
end



回答6:


Version change possibility : if you jump from the 2.1.x to the 3.x version of the gem via a non locked down bundle, you may have a similar issue.



来源:https://stackoverflow.com/questions/6641621/uninitialized-constant-delayedjob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!