Strange behavior with a resque scheduler job

岁酱吖の 提交于 2019-12-11 04:09:49

问题


so some context, I got some advice here:

Scheduling events in Ruby on Rails

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

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.

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. 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


回答1:


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.

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/



来源:https://stackoverflow.com/questions/15857412/strange-behavior-with-a-resque-scheduler-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!