I'm planning on making a simple service monitoring app with a web interface that will perform an http call every x minutes to a status page (per service), but I can't figure out which strategy would be the best. The two main strategies so far are:
我打算用一个Web界面制作一个简单的服务监控应用程序,每隔x分钟就会对一个状态页面(每个服务)执行一次http调用,但我无法确定哪种策略最好。目前的两个主要策略是:
- Do recursive calls with sleeps in them or
- Set up something like whenever or clockwork to evaluate some ruby code in a runner or rake task.
在他们或他们中进行休眠的递归调用
设置像什么时候或发条的东西来评估跑步者或耙子任务中的一些红宝石代码。
Neither strategy seems too efficient since whenever
has to spin up the rails environment for each task and I think sleep blocks.
这两种策略似乎都没有那么高效,因为每当必须为每项任务启动rails环境时,我认为睡眠阻塞。
Any suggestions would be very much appreciated.
任何建议将非常感谢。
2 个解决方案
#1
1
I can tell you my (little) experience with whenever and clockwork.
我可以告诉你我的(小)经验,无论什么时候和发条。
With whenever you setup your tasks (schedule) and use cron jobs of your OS to run you script(s).
无论何时设置任务(计划)并使用操作系统的cron作业来运行脚本。
Clockwork doesn't need cron jobs, it runs in an own ruby task, you can also configure clockwork over an own file.
发条不需要cron作业,它运行在自己的ruby任务中,你也可以在自己的文件上配置发条。
I would always prefer the cron/own task solution.
With your recursive calls approach you use the same log file as for your normal (productive) operations and it may blocks the server (long running task) and avoids clean up of your application (instance shutdown, ...). You'll have to determine that only one service is running in parallel and so on... . The cron/job solution is cleaner in every way.
我总是喜欢cron / own任务解决方案。使用递归调用方法,您可以使用与正常(生产)操作相同的日志文件,它可能会阻塞服务器(长时间运行的任务)并避免清理应用程序(实例关闭,...)。您必须确定只有一个服务并行运行,等等...... cron / job解决方案在各个方面都更加清洁。
I'm using clockwork because ruby is available on every environment and you don't have to set up a cron job. But this is a personal decision, if you prefer cron jobs, use them :) .
我正在使用发条,因为ruby可用于每个环境,而且您不必设置cron作业。但这是个人决定,如果您更喜欢cron工作,请使用它们:)。
#2
0
Neither strategy seems too efficient since whenever has to spin up the rails environment for each task
这两种策略似乎都不太高效,因为无论何时必须为每项任务启动rails环境
Actually, this is not true. whenever can be used independently of rails and will not spin up rails for each task. whenever will write to your cron file and let your system handle the task. whenever is just a dsl for cron. You can use whenever by simply entering
实际上,这不是真的。每当可以独立于轨道使用时,不会为每项任务旋转轨道。每当写入你的cron文件并让你的系统处理任务。无论何时只是cron的dsl。只需输入即可随时使用
whenever --update-crontab your_cron_name_here
每当--update-crontab your_cron_name_here
I'm going to reiterate what everyone said here and say that you want to use cron. However, if you use cron directly or with whenever is totally up to you. I personally prefer whenever but that's just me.
我要重申大家在这里说的话,并说你想用cron。但是,如果您直接使用cron,或者随时随地使用cron。我个人更喜欢,但那只是我。
#1
1
I can tell you my (little) experience with whenever and clockwork.
我可以告诉你我的(小)经验,无论什么时候和发条。
With whenever you setup your tasks (schedule) and use cron jobs of your OS to run you script(s).
无论何时设置任务(计划)并使用操作系统的cron作业来运行脚本。
Clockwork doesn't need cron jobs, it runs in an own ruby task, you can also configure clockwork over an own file.
发条不需要cron作业,它运行在自己的ruby任务中,你也可以在自己的文件上配置发条。
I would always prefer the cron/own task solution.
With your recursive calls approach you use the same log file as for your normal (productive) operations and it may blocks the server (long running task) and avoids clean up of your application (instance shutdown, ...). You'll have to determine that only one service is running in parallel and so on... . The cron/job solution is cleaner in every way.
我总是喜欢cron / own任务解决方案。使用递归调用方法,您可以使用与正常(生产)操作相同的日志文件,它可能会阻塞服务器(长时间运行的任务)并避免清理应用程序(实例关闭,...)。您必须确定只有一个服务并行运行,等等...... cron / job解决方案在各个方面都更加清洁。
I'm using clockwork because ruby is available on every environment and you don't have to set up a cron job. But this is a personal decision, if you prefer cron jobs, use them :) .
我正在使用发条,因为ruby可用于每个环境,而且您不必设置cron作业。但这是个人决定,如果您更喜欢cron工作,请使用它们:)。
#2
0
Neither strategy seems too efficient since whenever has to spin up the rails environment for each task
这两种策略似乎都不太高效,因为无论何时必须为每项任务启动rails环境
Actually, this is not true. whenever can be used independently of rails and will not spin up rails for each task. whenever will write to your cron file and let your system handle the task. whenever is just a dsl for cron. You can use whenever by simply entering
实际上,这不是真的。每当可以独立于轨道使用时,不会为每项任务旋转轨道。每当写入你的cron文件并让你的系统处理任务。无论何时只是cron的dsl。只需输入即可随时使用
whenever --update-crontab your_cron_name_here
每当--update-crontab your_cron_name_here
I'm going to reiterate what everyone said here and say that you want to use cron. However, if you use cron directly or with whenever is totally up to you. I personally prefer whenever but that's just me.
我要重申大家在这里说的话,并说你想用cron。但是,如果您直接使用cron,或者随时随地使用cron。我个人更喜欢,但那只是我。