简体   繁体   English

我应该使用cron job来执行此更新

[英]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. 现在我希望一旦达到endTime,拍卖会从active = 1更新为active = 2。 Is this best done by running a cron job once every minute? 最好每分钟运行一次cron作业吗? 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? 或者也许我根本不应该使用cron作业来完成这项任务?

The "buy-now" part is easy, if someone buys a item right away it sets active=2 right away. “立即购买”部分很容易,如果有人立即购买物品,它立即设置active = 2。

But I am not sure on how to automatically update auctions from active=1 to active=2 once the EndTime is reached. 但是我不确定如何在达到EndTime时自动将拍卖从active = 1更新为active = 2。

Also, my website is made in php/mysql, running on Linux lamp @ Ubuntu server 12.04. 另外,我的网站是用php / mysql制作的,运行在Linux灯@ Ubuntu服务器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 :) 在ubuntu上覆盖cron作业的stackoverflow上似乎有很多好的指南,但如果你有一个很好的指南请发布它以及:)

Thank you, 谢谢,

Don't use a cron job. 不要使用cron作业。 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. 如果用户实际上正在修改表,则将该功能包装在存储过程中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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