Ebtoulson
Ebtoulson

Reputation: 143

How to perform an http call every x minutes

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:

  1. Do recursive calls with sleeps in them or
  2. 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.

Any suggestions would be very much appreciated.

Upvotes: 0

Views: 126

Answers (2)

sunnyrjuneja
sunnyrjuneja

Reputation: 6123

Neither strategy seems too efficient since whenever has to spin up the rails environment for each task

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

whenever --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.

Upvotes: 0

Eich
Eich

Reputation: 3788

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).

Clockwork doesn't need cron jobs, it runs in an own ruby task, you can also configure clockwork over an own file.

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.

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 :) .

Upvotes: 1

Related Questions