延迟作业:未初始化的常量错误

时间:2017-07-17 12:39:59

标签: ruby-on-rails ruby ruby-on-rails-4 delayed-job

我正在尝试使用延迟作业保存pdf。以下是迄今为止所做的工作。

的Gemfile

gem 'delayed_job', '~> 4.1', '>= 4.1.3'
gem 'delayed_job_active_record', '~> 4.1', '>= 4.1.2'
gem "daemons"

然后运行命令

rails generate delayed_job:active_record
rake db:migrate

配置/ application.rb中

config.active_job.queue_adapter = :delayed_job

初​​始化/ delayed_job_config.rb

Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.sleep_delay = 60
Delayed::Worker.max_attempts = 10
Delayed::Worker.max_run_time = 5.minutes
Delayed::Worker.read_ahead = 10
Delayed::Worker.default_queue_name = 'default'
Delayed::Worker.delay_jobs = !Rails.env.test?
Delayed::Worker.raise_signal_exceptions = :term
Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))

然后在控制器

def save_file
 @articles = Article.all
 @articles.each do |article|
  Delayed::Job.enqueue(SaveArticle.new(article.id))
 end
end

和SaveArticle.rb

class SaveArticle < ActiveRecord::Base
  def perform(article_id)
    pdf = GeneratePdf.new(article_id)
    pdf.render_file(article_id.to_s + ".pdf")
  end
end

这给了我错误

uninitialized constant MyController::GeneratePdf

我在这里做错了什么?

0 个答案:

没有答案