1

我正在使用数据库事件和 resque 对特定任务进行排队,但它看起来像是多次将作业排队:

16:27:00 scheduler.1 | I, [2014-09-21T16:27:00.916001 #21736]  INFO -- : Triggering 'TimeSlot:6'
16:27:35 scheduler.1 | I, [2014-09-21T16:27:35.035227 #21736]  INFO -- : Triggering 'sync_database_events_for_model_TimeSlot'
16:27:36 scheduler.1 | I, [2014-09-21T16:27:36.039108 #21736]  INFO -- : Triggering 'TimeSlot:6'

注意时间戳,它会在每分钟(来自对象的时间戳)对作业进行一次排队,并在发条与数据库同步后再次排队。

这是我的clock.rb:

require File.expand_path('../../config/boot',        __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'clockwork'
require 'clockwork/database_events'
require 'clockwork/database_events/manager'

module Clockwork
  # required to enable database syncing support
  Clockwork.manager = DatabaseEvents::Manager.new

  sync_database_events model: TimeSlot, every: 1.minute do |time_slot|
    # Send emails with Resque
    time_slot.queue_reminder
  end
end

和time_slot.rb:

class TimeSlot < ActiveRecord::Base
  belongs_to :person

  def queue_reminder
    Resque.enqueue(TimeSlotReminder, person.id, id)
  end

  def frequency
    # one week in seconds
    604800
  end

  def at
    "#{day} #{time.strftime('%H:%M')}"
  end
end

感谢您的关注!

4

0 回答 0