Without delayed_job, this code works fine; if I enable delayed_job, I get an uninitialized constant EmailNewsletter::Gibbon error with every attempt the worker makes.
Rails 3.0.7, Gibbon 0.1.5 (a gem for working with MailChimp), delayed_job 2.1.4.
controller
def subscribe email = params[:email] EmailNewsletter.subscribe(email) render(:update) do |page| page << "...view update code..." end end
Library / email _newsletter.rb
module EmailNewsletter def self.subscribe(email) g = Gibbon::API.new('api_key_here', :id => 'list_id_here') g.listSubscribe(:email_address => email) end end
With the code above, if I send the email address to / subscribe, everything works fine. I want to enable delayed_job so that my application does not feel slow if MailChimp responds too quickly.
controller
def subscribe email = params[:email] EmailNewsletter.delay.subscribe(email) render(:update) do |page| page << "...view update code..." end end
It seems like the work goes into the delayed_job table just fine. handler data:
--- !ruby/struct:Delayed::PerformableMethod object: !ruby/module EmailNewsletter method_name: :subscribe args: - email@example.com
After a second, the worker selects and starts, and I get an error message: uninitialized constant EmailNewsletter::Gibbon .
application.rb includes config.autoload_paths += %W(#{Rails.root}/lib) .
What am I doing wrong?
Edit
To clarify the line on which the error is thrown, is
g = Gibbon::API.new('api_key_here', :id => 'list_id_here')
I also tried
g = ::Gibbon::API.new('api_key_here', :id => 'list_id_here')
ruby-on-rails ruby-on-rails-3 delayed-job
jaacob
source share