Error using Gibbon gem via delayed_job?

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')

+8
ruby-on-rails ruby-on-rails-3 delayed-job
source share
2 answers

he just can't find the Gibbon libraries

 require 'gibbon' #in the module to help it find it 

-7 months later but hey

Or even better, there is no Gibbon :: API class, Gibbon itself is a class, not a module.

 api = Gibbon.new("abc123-us2") 
+2
source share

You have included gemfile in the file with a delay_job. Can you try this one time.

  gem 'delayed_job' 
0
source share

All Articles