我使用数据库事件和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
谢谢你的期待!