[英]Strange behavior with a resque scheduler job
so some context, I got some advice here: 所以在某些情况下,我在这里得到了一些建议:
aand have been tying to implement it today. aand一直在努力实施它。 I cant seem to make it work though.
我似乎无法使其工作。 this is my scheduler job that is used to move my questions around between a delayed queue and a ready to send out queue (i've since decided to use email instead of SMS)
这是我的调度程序作业,用于在延迟的队列和准备发送的队列之间移动我的问题(此后,我决定使用电子邮件代替SMS)
require 'Assignment'
require 'QuestionMailer'
module SchedulerJob
@delayed_queue = :delayed_queue
@ready_queue
def self.perform()
@delayed_queue.each do |a|
if(Time.now >= a.question.schedule)
@ready_queue << a
@delayed_queue.delete(a)
end
end
push_questions
end
def self.gather()
assignments = Assignment.find :all
assignments.each do |a|
@delayed_queue << a unless @delayed_queue.include? a
end
end
private
def self.push_questions
@ready_queue.each do |a|
QuestionMailer.question(a)
end
end
end
I use a callback on_create to call the gather method every time an assignment is created, and then the perform action actually does the sending of emails when resque runs. 每次创建分配时,我都使用回调on_create来调用collect方法,然后在resque运行时,perform操作实际上会发送电子邮件。
I'm getting a strange error from the callback though. 我从回调中收到一个奇怪的错误。
undefined method `include?' for :delayed_queue:Symbol
here is the code from the assignment model 这是分配模型中的代码
class Assignment < ActiveRecord::Base
belongs_to :user
belongs_to :question
attr_accessible :title, :body, :user_id, :question_id , :response , :correct
after_create :queue_assignments
def grade
self.correct = (response == self.question.solution) unless response == nil
end
def queue_assignments
SchedulerJob.gather
end
Any ideas what's going on? 有什么想法吗? I think this is a problem with my understanding of how these queue's work with resque-scheduler.
我认为这是我对这些队列如何与resque-scheduler一起工作的理解的问题。 I assumed that if the queues were list-like objects then I could operate on them , but it appears that it a symbol instead of something with methode like include?
我以为如果队列是类似列表的对象,那么我可以对其进行操作,但是似乎它是一个符号,而不是诸如include之类的方法的东西? I assume the << notation for adding something to it is also invalid.
我认为添加内容的<<符号也是无效的。 Also please advise if this isn't the way to go about handling this kind of job scheduling
还请告知这是否不是处理此类作业计划的方法
It appears you may have not restarted your Rails app after adding the new method gather
to the SchedulerJob
module. 将新方法
gather
添加到SchedulerJob
模块后,您似乎尚未重启Rails应用。 Try restarting your app to resolve this. 尝试重新启动您的应用以解决此问题。
You may also be able to add the directory containing your Resque worker to Rails' watchable_dirs
array so that changes you make to Resque worker modules in development don't require restarting your app. 您也可以将包含Resque工作程序的目录添加到Rails的
watchable_dirs
数组中,以便在开发中对Resque工作程序模块进行的更改不需要重启应用程序。 See this blog post for details: 有关详细信息,请参见此博客文章:
http://wondible.com/2012/01/13/rails-3-2-autoloading-in-theory/
http://wondible.com/2012/01/13/rails-3-2-autoloading-in-theory/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.