On Tue, Apr 09, 2002 at 08:06:08PM -0700, Zachary Buckholz wrote:
> I am having a hard time with a logic problem related to scheduling an event
> based on data stored in a MySQL table. Below is a sample data set.
> The basic concept is a monitoring program that checks a website to see if
> its up or down based on info stored in a table.
> The way I am doing it requires me to know the last time the site was checked
> and how often the site should be checked. I threw in the nc_epoch (next
> check epoch seconds) while trying to work through this. That field can be
> ignored, unless you see a solution using it.
> 
> mc_id = customer id related to another table
> url_id = url_id related to another table
> chk_freq = how often in seconds the site should be checked
> url_timeout = how long to wait for website before considering it down
> lc_epoch = last time the site was checked - converted to UNIX epoch in DBI
> query
> active = is the site supposed to be checked
> nc_epoch = next time the site should be checked - converted to UNIX epoch in
> DBI query

If you have a column that says when the next check should occur, that's
probably the column you should use:

select * from table where nc_epoch <= now

And then, for each of the rows:

update table set lc_epoch = now, nc_epoch = now + chk_freq
where mc_id = ? and url_id = ?


Of course, you can ignore nc_epoch and just use lc_epoch and chk_freq if
you prefer:

select * from table where lc_epoch + chk_freq <= now

update table set lc_epoch = new
where mc_id = ? and url_id = ?


I don't know if you can index the sum of two columns, however.


Ronald

Reply via email to