Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Delayed Job & Library Class

Hey we have a library class (lib/Mixpanel) that calls delayed job as follows:

class Mixpanel

  attr_accessor :options
  attr_accessor :event

  def track!()
   .. 
   dj = send_later :access_api # also tried with self.send_later
   ..
  end

  def access_api
   ..
  end

The problem is that when we run rake jobs:work: we get the following error:

undefined method `access_api' for #<YAML::Object:0x24681b8>

Any idea why?

like image 259
LMH Avatar asked Apr 02 '10 21:04

LMH


1 Answers

Delayed_job always autoloads ActiveRecord classes, but it doesn't know about other types of classes (like lib) that it has marshaled in the db as YML. So, you need to explicitly trigger the class loader for them. Since DJ starts up the Rails environment, just mention any non-AR marshaled classes in an initializer:

(config/initializers/load_classes_for_dj.rb)

Mixpanel
like image 130
Jonathan Julian Avatar answered Sep 24 '22 11:09

Jonathan Julian