每月必须经营一次这项工作。无论何时宝石,我都需要在cron中调用它。 在这种情况下使用工作或耙?
我无法在控制台中完成我的工作。
rails runner'MyJob.perform_later'
我正在使用Rails 4.2
错误:
.rvm / gems / ruby-2.1.4 / gems / railties-4.2.0 / lib / rails / commands / runner.rb:62:in <top (required)>': uninitialized constant MyJob (NameError)
from /Users/leonardo/.rvm/gems/ruby-2.1.4/gems/railties-4.2.0/lib/rails/commands/runner.rb:62:in
eval'
来自/Users/leonardo/.rvm/gems/ruby-2.1.4/gems/railties-4.2.0/lib/rails/commands/runner.rb:62:in <top (required)>'
from /Users/leonardo/.rvm/gems/ruby-2.1.4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123:in
require'
来自/Users/leonardo/.rvm/gems/ruby-2.1.4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123:in require_command!'
from /Users/leonardo/.rvm/gems/ruby-2.1.4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:90:in
runner'
来自/Users/leonardo/.rvm/gems/ruby-2.1.4/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in run_command!'
from /Users/leonardo/.rvm/gems/ruby-2.1.4/gems/railties-4.2.0/lib/rails/commands.rb:17:in
'
来自bin / rails:4:require'
from bin/rails:4:in
'
我的工作内容:
类MyJob&lt; ActiveJob ::基地 queue_as:默认
def perform()
Veiculo.particulares.publicado.each do |veiculo|
limite_dias = veiculo.plano.dias_ativado
dias_ativado = DateTime.today - veiculo.ativado_em.to_date
if limite_dias > dias_ativado
veiculo.update_attribute(:ativo, nil)
VeiculoMailer.avisa_desativacao(veiculo).deliver_later
end
end
end
端