有没有办法“观看”使用 rake 任务插入新数据库表?
我有 rufus 调度程序,我计划查看我的日程表以获取新的日程安排。有办法做到这一点吗?类似于:
schedule.every "1m" do
#check for new entries in database
end
已回答
scheduler.every '1m' do
#check for new stuff in the database
newest_jobs = Schedule.all_cron_jobs.select{ |x| x.created_at > 1.minute.ago } - all_schedules_with_cron
unless newest_jobs.empty?
newest_jobs.each do |new_job|
scheduler.every new_job.cron_string do
job.call
end
end
end
end
jobs.call 是对延迟作业的调用,以对该计划进行排队。所以基本上,获取最新的计划,并在每次 cron 匹配时调用 rufus 将作业放入队列
I have rufus scheduler and i was planning to watch my schedules table for new schedules. Is there a way to do that? something like:
schedule.every "1m" do
#check for new entries in database
end
ANSWERED
scheduler.every '1m' do
#check for new stuff in the database
newest_jobs = Schedule.all_cron_jobs.select{ |x| x.created_at > 1.minute.ago } - all_schedules_with_cron
unless newest_jobs.empty?
newest_jobs.each do |new_job|
scheduler.every new_job.cron_string do
job.call
end
end
end
end
jobs.call is a call to delayed job to queue that schedule. So basically, get the newest schedules, and call rufus on them to put the jobs on queue every time the cron matches
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用表中的
created_at
列检查自上次检查以来是否有新条目。您可以通过进一步最小化
last_checked
周期之间的间隙来改进这一点。在模型上使用观察者不是更好吗?保证不会因时间问题而错过。
Use the
created_at
column on the table to check for new entries since you last checked.You could improve this by minimising the gap between
last_checked
cycles even more.Would you not be better to use an observer on the model instead of this? Guarantees no misses due to timing issues.