我试图在控制台中调用一个工作但总是出错。
遵循以下文档:
创建以下文件:(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'for#
如果我试试这个:
Jobs::ArchiveSurveysJob.perform(`string_here`)
要么:
Jobs::ArchiveSurveysJob.perform_now('string_here')
我明白了:
ArgumentError:参数数量错误(给定0,预期1..2)
如果我遗漏了一些文件或者我做错了,请告诉我。
我如何设法做到这一点是通过创建一个Rake任务并在那里调用Job。