resque 调度程序作业的奇怪行为 [英] Strange behavior with a resque scheduler job

查看:43
本文介绍了resque 调度程序作业的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

so some context, I got some advice here:

在 Ruby on Rails 中安排事件

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

aand have been tying to implement it today. 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)

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 运行时发送电子邮件.

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.

不过,我从回调中收到了一个奇怪的错误.未定义的方法`include?':delayed_queue:Symbol

I'm getting a strange error from the callback though. 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 一起工作的理解的问题.我假设如果队列是类似列表的对象,那么我可以对它们进行操作,但它似乎是一个符号而不是像包含这样的方法的东西?我假设 <<添加一些东西的符号也是无效的.另外请告知这是否不是处理此类作业调度的方法

Any ideas what's going on? I think this is a problem with my understanding of how these queue's work with 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? 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

推荐答案

在将新方法 gather 添加到 SchedulerJob 后,您似乎没有重新启动 Rails 应用程序模块.尝试重新启动您的应用以解决此问题.

It appears you may have not restarted your Rails app after adding the new method gather to the SchedulerJob module. Try restarting your app to resolve this.

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

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. See this blog post for details:

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

这篇关于resque 调度程序作业的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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