Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图弄清楚为什么这不起作用:
loop do started = Time.now # do stuff ended = Time.now - started if 5.minutes > ended sleep ended end end
当前代码休眠的时间长度与原始进程所用的时间相同(的值ended)。这使得整个循环时间一半“做事”,一半睡觉。您可能应该将睡眠线更改为
ended
sleep 5.minutes - ended
相反,如果我正确理解了这个问题,并且您希望每 5 分钟运行一次该过程,并考虑到完成所需的时间。
cron如果进入循环的设置时间不太长,您可能需要考虑改用。
cron