Delayed_job(2.1.4)错误:作业加载失败:需要IO实例.处理程序无 [英] Delayed_job (2.1.4) error: Job failed to load: instance of IO needed. Handler nil

查看:89
本文介绍了Delayed_job(2.1.4)错误:作业加载失败:需要IO实例.处理程序无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的成就系统,并希望引入延迟工作(2.1.4)来进行处理.但是,delayed_jobs表中的处理程序列始终为nil,这将导致last_error文本:Job failed to load: instance of IO needed. Handler nil

I created a simplistic achievements system and wanted to introduce delayed_job (2.1.4) to take care of the processing. However, the handler column in the delayed_jobs table is always nil, which results in the last_error text: Job failed to load: instance of IO needed. Handler nil

这是我的设置:

成就观察者

class AchievementObserver < ActiveRecord::Observer
  observe User, Comment, ...

  def after_create(record)
    # initiate delayed job to check conditions
    Delayed::Job.enqueue(TrophyJob.new(record.id, record.class.name))
  end
  ...
end

奖杯工作

class TrophyJob < Struct.new(:record_id, :record_type)
  def perform
    case record_type
    when "User"
      UserProfileCompleteTrophy.progress(User.find(record_id)) # complete your profile settings
      NewsletterReceiverTrophy.progress(User.find(record_id)) # sign up for the newsletter
    when "Comment"
      CommentsAuthoredTrophy.progress(Comment.find(record_id)) # create x comments
    ...
    end
  end
end

delayed_jobs表中的条目已创建.但是,处理程序始终为NULL.我已经尝试过各种方法(之前已经通过了完整的对象,现在按如下所述使用id + classname:

The entry in the delayed_jobs table gets created. However, the handler is always NULL. I've already tried various things (passed through complete objects before, now went for id + classname as described here: Weird exception with delayed_job; tried xxxTrophy.delay.progress(...) in the observer; etc.) - all without luck.

我也有

require 'yaml'
YAML::ENGINE.yamler= 'syck'

在我的boot.rb中.

in my boot.rb.

值得一提的是:尽管last_error文本被delay_job填充,但try和failed_at列仍为NULL.

One thing worth mentioning: Although the last_error text gets filled by delayed_job, the attempts and failed_at columns remain NULL.

我想念什么?

更新

我验证了序列化的工作符合人们的预期:

I verified that serialization works as one would expect:

ruby-1.9.2-p290 :004 > TrophyJob.new(1, "User").to_yaml
 => "--- !ruby/struct:TrophyJob \nrecord_id: 1\nrecord_type: User\n"

推荐答案

找到了解决方案:我的问题是由大规模分配保护引起的.我有一个初始化程序来防止大规模分配:

Found the solution: my problem was caused by mass-assignment protection. I have an initializer to protect against mass-assignment:

# SECURITY: protect against mass assignment vulnerabilities
# enforces explicitly setting attributes accessible in models (whitelisting)
ActiveRecord::Base.send(:attr_accessible, nil)

这阻止了delay_job访问处理程序字段!不确定是否可以将其视为DJ中的错误.这是解决我的问题的初始化代码:

This prevented delayed_job to access the handler field! Not sure if this can be considered a bug in DJ. Here is the initializer code that solved my problem:

# Imortant: delayed job requires some attributes to be accessible - make sure they are
Delayed::Job.attr_accessible :priority, :payload_object, :handler, :run_at, :failed_at

这篇关于Delayed_job(2.1.4)错误:作业加载失败:需要IO实例.处理程序无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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