Rails 应用程序中的 Enqueue_at(..) 错误.Resque 调度程序引发 NoQueueError [英] Enqueue_at(..) error in rails app. Resque scheduler raises NoQueueError
问题描述
我在尝试使用 ResqueScheduler enqueue_at 时不断收到此错误
Resque::NoQueueError in QuestionsController#create作业必须放在队列中.
这是调用它的类:注意 after_create 回调.
在 Questions 控制器中引发错误的原因是因为 Question
有一个回调 on_create
,它反过来创建了一个 Assignment
供用户使用.
这是这篇文章的后续问题:
我已尝试按照此视频中给出的示例进行操作:http://railscasts.com/episodes/271-resque?view=comments
...以及阅读我在 Resque scheduler online 上可以找到的基本上所有内容(包括他们的文档:https://github.com/bvandenbos/resque-scheduler)
我有理由相信我做得对,但此时非常沮丧.这似乎是一个非常罕见的在线错误,文档很少.
<前>需要scheduler_job"类赋值 ActiveRecord::Base归属地:用户归属地:问题attr_accessible :title, :body, :user_id, :question_id , :response , :correctafter_create :queue_assignmentsbefore_destroy :remove_from_queue定义等级self.correct = (response == self.question.solution) 除非 response == nil结尾def queue_assignmentsResque.enqueue_at(self.question.schedule , SchedulerJob , :id => self.id)结尾def remove_from_queueResque.remove_delayed(SchedulerJob, :id => self.id)结尾定义发送警报电子邮件QuestionMailer.question(self)结尾def as_json(options={}){:正确 => 正确,:created_at => created_at,:id => id,:question_id => question_id,:响应 => 响应,:updated_at => updated_at,:user_id => user_id,:question => self.question}结尾结尾这是工作:
<前>需要分配"需要 'QuestionMailer'# 当我把它改成一个类时这也不起作用模块调度器作业#this 也不适用于 :ready_queue 但我不知道有什么区别@ready_queue = "ready_queue"def self.perform(id)@assignment=Assignment.find_by_id(id)@assignment.sendAlertEmail结尾结尾好的,经过大量的故障排除和我的头撞墙,我终于让它工作了.
实例变量必须命名为@queue
.问题是我将它命名为 @ready_queue
.我猜 resque 调度程序需要这个.反正.它现在似乎正在工作.继续下一个错误.
I keep getting this error while trying to use ResqueScheduler enqueue_at
Resque::NoQueueError in QuestionsController#create Jobs must be placed onto a queue.
Here is the class that's calling it: note the after_create callback.
The reason the error is raised in the Questions controller is because there is a callback on_create
for Question
which in turn, creates an Assignment
for users.
This is a follow-up issue from this post:
Strange behavior with a resque scheduler job
I've tried to follow the examples givien in this video: http://railscasts.com/episodes/271-resque?view=comments
. . .as well as reading basically everything I can find on Resque scheduler online, (including their documentation here: https://github.com/bvandenbos/resque-scheduler)
I am reasonably confident that I am doing this right and pretty frustrated at this time. This seems to be a pretty rare error online with little documentation.
require "scheduler_job" class Assignment ActiveRecord::Base belongs_to :user belongs_to :question attr_accessible :title, :body, :user_id, :question_id , :response , :correct after_create :queue_assignments before_destroy :remove_from_queue def grade self.correct = (response == self.question.solution) unless response == nil end def queue_assignments Resque.enqueue_at(self.question.schedule , SchedulerJob , :id => self.id) end def remove_from_queue Resque.remove_delayed(SchedulerJob, :id => self.id) end def sendAlertEmail QuestionMailer.question(self) end def as_json(options={}) { :correct => correct, :created_at => created_at, :id => id, :question_id => question_id, :response => response , :updated_at => updated_at, :user_id => user_id, :question => self.question } end end
And here is the job:
require 'Assignment' require 'QuestionMailer' # this didnt work when i changed it to a class either module SchedulerJob #this didnt work with :ready_queue either but I dont know what the difference is @ready_queue = "ready_queue" def self.perform(id) @assignment=Assignment.find_by_id(id) @assignment.sendAlertEmail end end
Ok so after a ton of troubleshooting and banging my head against the walls, I finally got it to work.
The instance variable Must be named@queue
. The problem was that I was naming it @ready_queue
. I guess resque scheduler requires this. Anyway. It seems to be working now. on to the next bug.
这篇关于Rails 应用程序中的 Enqueue_at(..) 错误.Resque 调度程序引发 NoQueueError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!