Without delayed_job, this code works fine; if I include delayed_job, I get an error of uninitialized constant EmailNewsletter::Gibbon
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
lib/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 above code, if I post an email address to /subscribe, everything works fine. I want to incorporate delayed_job so that my app doesn't feel slow if MailChimp takes a beat too long to respond.
Controller
def subscribe
email = params[:email]
EmailNewsletter.delay.subscribe(email)
render(:update) do |page|
page << "...view update code..."
end
end
It looks like the job goes into the delayed_job table just fine. The handler
data is:
--- !ruby/struct:Delayed::PerformableMethod
object: !ruby/module EmailNewsletter
method_name: :subscribe
args:
- [email protected]
A second later the worker picks it up and runs, and I get an error: uninitialized constant EmailNewsletter::Gibbon
.
application.rb
includes config.autoload_paths += %W(#{Rails.root}/lib)
.
What am I doing wrong?
Edit
For clarification, the line that the error is being thrown on is
g = Gibbon::API.new('api_key_here', :id => 'list_id_here')
I have also tried
g = ::Gibbon::API.new('api_key_here', :id => 'list_id_here')
it just can't find the Gibbon libs
require 'gibbon' #in the module to help it find it
-7 months later, but hey
Or better yet, there is no Gibbon::API class, Gibbon itself is the class, not a module.
api = Gibbon.new("abc123-us2")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With