问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/15857868/enqueue-at-error-in-rails-app-resque-scheduler-raises-noqueueerror