3

需要每月运行一次作业。我需要在 cron 中使用 gem 调用它。在这种情况下使用工作或耙子?

我无法在控制台中运行我的工作。

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:ineval' 来自 /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来自 /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:inrunner' 来自 /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:in require' from bin/rails:4:in'

我的工作内容:

类 MyJob < ActiveJob::Base queue_as :default

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

结尾

4

0 回答 0