user2654458
user2654458

Reputation: 23

Should I use cron job to do this update

Im working on letting my users start auctions on my website, but om not sure on how I should update a auction to "not active" from active.

In the database every auction has a row called "active"

"active=1"      Means the auction is active
"active=2"      Means the auction is NOT active.

Now I want auctions to update from active=1, to active=2 once the endTime is reached. Is this best done by running a cron job once every minute? Or would it slow down my site alot if I run it every minute.

Or maybe I shouldnt use cron jobs at all to do this task?

The "buy-now" part is easy, if someone buys a item right away it sets active=2 right away.

But I am not sure on how to automatically update auctions from active=1 to active=2 once the EndTime is reached.

Also, my website is made in php/mysql, running on Linux lamp @ Ubuntu server 12.04.

There seem to be alot of good guides here on stackoverflow covering cron jobs on ubuntu, but if you have a good guide please post it aswell :)

Thank you,

Upvotes: 0

Views: 203

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270463

Don't use a cron job. Put the logic in a view:

create view vw_auctions as
    select a.*,
           (case when enddatetime >= now() then 2 else 1 end) as ActiveFlag
    from auctions;

Then, all access to the table should be through the view. If users are actually modifying the table, then wrap that functionality in stored procedures.

Upvotes: 2

Related Questions