当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby - Is while loop a good practice for cronjob alternative

问题描述:

I want to run the following task as a daemon (infinite loop)

restart the docker containers and its tasks every 6:00 and 12:00

while true

docker-compose up

docker exec EZUSer_star_1 ruby star/star.rb&

docker exec EZUSer_tiger_1 ruby tiger/tiger.rb&

BUSY_WAITING_HERE except if 6:00 or 12:00 then just keep going

docker-compose down

end

Is there any suggestion to gurantte the above job can run for months or years ?

I don't want to do it with cron

I need application level cronjob-like library

Is there any Ruby DSL or library can let me do the kind_of job easier or robust.

网友答案:

If you are looking for a Ruby scheduler, Rufus Scheduler is the best one that I know about.

https://github.com/jmettraux/rufus-scheduler

网友答案:

running it in a forever loop is probably not a good idea. In general, bad things happen to well-behaved processes all the time (oom killer, failure that leaves things in a dirty state you cannot recover from without releasing all resources, etc).

If you want to go ahead, make sure that you have something (externally) that checks if the process is running and restarts it (supervisord/monit/etc).

分享给朋友:
您可能感兴趣的文章:
随机阅读: