resque 调度程序作业的奇怪行为

2024-03-08

所以一些背景,我在这里得到了一些建议:

在 Ruby on Rails 中安排事件 https://stackoverflow.com/questions/15710013/scheduling-events-in-ruby-on-rails

今天我们一直致力于实施它。但我似乎无法让它发挥作用。这是我的调度程序工作,用于在延迟队列和准备发送队列之间移动我的问题(此后我决定使用电子邮件而不是短信)

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

每次创建分配时,我都会使用回调 on_create 来调用 Gather 方法,然后执行操作实际上会在 resque 运行时发送电子邮件。

不过,我从回调中收到了一个奇怪的错误。undefined method `include?' for :delayed_queue:Symbol

这是分配模型中的代码

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

有什么想法吗?我认为这是我对这些队列如何与 resque-scheduler 一起工作的理解的问题。我假设如果队列是类似列表的对象,那么我可以对它们进行操作,但它似乎是一个符号,而不是像 include 这样的方法的东西?我假设向其中添加内容的


添加新方法后,您可能尚未重新启动 Rails 应用程序gather to the SchedulerJob模块。尝试重新启动您的应用程序来解决此问题。

您还可以将包含 Resque 工作线程的目录添加到 Rails 的watchable_dirs数组,以便您在开发过程中对 Resque 工作模块所做的更改不需要重新启动应用程序。有关详细信息,请参阅此博文:

http://wondible.com/2012/01/13/rails-3-2-autoloading-in-theory/ http://wondible.com/2012/01/13/rails-3-2-autoloading-in-theory/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

resque 调度程序作业的奇怪行为 的相关文章

随机推荐