Ruby:力兰德频率
我必须在随机选择的时间运行一段代码,但例如我必须每天运行一次。该程序并不是一直运行,所以我不能真正强迫它每小时运行并执行类似 if rand(1..24) == 1
我怎样才能设法拥有这种类型频率而不是一直运行?
I have to run a piece of code at randomly chosen times but I have to run it about once a day for instance. The program is not running all time so I can't really force it to run every hour and do something like if rand(1..24) == 1
How can I manage to have this kind of frequency without running it all time ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
程序以某种方式需要考虑自上次运行以来所经过的时间,因此未执行的时间越长,程序执行的可能性就越大。使用睡眠的示例:
The program somehow needs to take the passed time since the last run into consideration, so that it gets more likely that it executes the longer it has not executed. Example using sleep: