Rails延迟的工作&图书馆课 [英] Rails Delayed Job & Library Class

查看:48
本文介绍了Rails延迟的工作&图书馆课的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我们有一个库类(lib / Mixpanel),它按以下方式调用延迟的作业:

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

问题是当我们运行rake jobs:work时,出现以下错误:

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

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

知道为什么吗?

推荐答案

Delayed_job总是自动加载ActiveRecord类,但它不知道它已作为YML在数据库中编组的其他类型的类(如lib)。因此,您需要为它们显式触发类加载器。由于DJ启动了Rails环境,因此只需在初始化程序中提及所有非AR编组类:

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

这篇关于Rails延迟的工作&amp;图书馆课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆