Rails Delayed Job & Library Class

前端 未结 2 855
北荒
北荒 2020-12-09 21:57

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

class Mixpanel

  attr_accessor :options
  attr_accessor :event

  def track!()         


        
相关标签:
2条回答
  • 2020-12-09 22:17

    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
    
    0 讨论(0)
  • 2020-12-09 22:29

    A small gotcha, I followed Jonathan's suggestion, but I needed to add a require before the class name, so I'd use this for load_classes_for_dj.rb:

    require 'mixpanel'
    Mixpanel
    

    Then it worked fine!

    0 讨论(0)
提交回复
热议问题