我试图弄清楚如何能够做到以下几点。
我想每天下午 12:00 开始一项工作,计算一个事物列表,然后分批处理这些事物,大小为“b”。并保证一个批次的结束和另一个批次的开始之间有 x 分钟的间隔。
schedule.cron '00 12 * * *' do
# things = Compute the list of things
schedule.interval '10m', # Job.new(things[index, 10]) ???
end
我尝试了类似以下的方法,但我讨厌我必须将调度程序传递给作业或访问单例调度程序。
class Job < Struct.new(:things, :batch_index, :scheduler)
def call
if (batch_index+1) >= things.length
ap "Done with all batches"
else
# Process batch
scheduler.in('10m', Dummy.new(things, batch_index+1, scheduler))
end
end
end
scheduler = Rufus::Scheduler.new
schedule.cron '00 12 * * *' , Dummy.new([ [1,2,3] , [4,5,6,7], [8,9,10]], 0, scheduler)