I开发者_Python百科 am trying to find out how to run a ruby script(method) every hour on the hour and to have it quit upon key pressed. I have been trying to loop but it seems to run many times during the same second.
Try Ruby Whenever gem.
The function you want is sleep
A better idea might be to have your script complete rather than loop, and write its output to a file you can check later rather than pressing a key to close. Then launch the script hourly using crontab.
Well, there's a few things to consider, you'll have to sleep and you'll have to accept a keypress immediately to stop. So you'll probably want two threads, one that loops looking for key presses and the other than sleeps and actually performs the action every hour.
I'm a bit of a ruby n00b, so that's what you need conceptually (two threads, one using sleep) but if you need implementation details I'll have to do some research.
Please used Daemons gem.
加载中,请稍侯......
精彩评论