简体   繁体   中英

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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM