Rails延迟了两次作业

时间:2018-02-05 21:05:28

标签: ruby-on-rails delayed-job rails-activejob

我添加了delayed_job gem并创建了一个简单的ActiveJob。我在工作结束后将记录插入数据库。当我检查表时,我看到2条记录。我在控制台中看到以下几行。

[Worker(host:k pid:4962)] Job SimpleJob (id=9305) (queue=Default) RUNNING
[Worker(host:k pid:4962)] Job SimpleJob (id=9305) (queue=Default) COMPLETED after 0.7371
[Worker(host:k pid:4962)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=9306) (queue=Default) RUNNING
[Worker(host:k pid:4962)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=9306) (queue=Default) COMPLETED after 0.5055
[Worker(host:k pid:4962)] 2 jobs processed at 1.5728 j/s, 0 failed

为什么我的工作会跑两次?我该如何解决这个问题?

编辑:以下代码是我的ActiveJob代码。我在SimpleJob.schedule!中添加了config/initializers/job_initializars.rb行,以便首次启动。

class SimpleJob < ActiveJob::Base

include Delayed::RecurringJob
  run_every 1.minute
  queue 'Default'

  def perform
    begin   
      Vehicle.where(number_plate: lo."12345" ).update_all(:longitude => "47", :latitude => "33")

    rescue => ex
      Delayed::Worker.logger.info "---------------->" +  ex.message
    end

  end
end

0 个答案:

没有答案