【发布时间】:2019-07-31 23:33:38
【问题描述】:
我试图在控制台中调用作业,但总是出错。
遵循以下文档:
- http://tutorials.jumpstartlab.com/topics/performance/background_jobs.html
- https://www.youtube.com/watch?v=UrE47tCrZXc
- https://guides.rubyonrails.org/active_job_basics.html
- https://github.com/resque/resque
- How can I run an ActiveJob in Rails console for debugging?
创建了以下文件: (lib/jobs/archive_survey_jobs.rb)
module Jobs
class ArchiveSurveysJob < ActiveJob::Base
@queue = :setup
def perform(survey_type)
if SurveyTypes.all_classes.map(&:to_s).include?(survey_type)
surveys = Survey.where(something: 'stuff')\
.where.not(something: 'stuff',
something: 'stuff')
surveys.each do |survey|
do_something
end
end
end
end
end
我知道我可以做类似Resque.enqueue(ArchiveSurveysJob, 'string_here')的事情
如何在控制台中调用它?如果我尝试:
Jobs::ArchiveSurveysJob.create(survey_type: 'string_here'),
当我检查 Resque 状态时,它导致错误:`任务因错误而失败:
用于#的未定义局部变量或方法`args'
如果我试试这个:
Jobs::ArchiveSurveysJob.perform(`string_here`)
或者:
Jobs::ArchiveSurveysJob.perform_now('string_here')
我明白了:
ArgumentError:参数数量错误(给定 0,预期 1..2)
如果我遗漏了一些文档或者我做错了什么,请告诉我。
【问题讨论】:
-
你为什么把这个类放在一个模块中?您是否尝试过在模块外运行
perform_now? -
@GrahamSlick 如果我将其从模块中删除并运行:
ArchiveSurveysJob.perform_now(string_here')` 我 ged:uninitialized constant ArchiveSurveysJob -
Jobs::ArchiveSurveysJob.perform_now('string_here')应该可以工作。
标签: ruby-on-rails ruby resque resque-scheduler resque-status