我试图在控制台中调用作业,但总是出错。
遵循以下文档:
- 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
- 如何在 Rails 控制台中运行 ActiveJob 进行调试?
创建了以下文件:(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)
如果我遗漏了一些文档或者我做错了什么,请告诉我。