Jump to content

Recommended Posts

Hi all,

 

So here is the scenario

 

1: User 1 reports A, B, or C

2: User 2 has 24 hours to confirm(or reject) what User 1 reported.

2a: If User 2 does not report within 24 hours, User 1 report is considered true.

 

I am using PHP + MySQL. Can anyone advise what they would do to tackle this scenario?

 

Thanks,

Ryan

 

So I set a timestamp up for that purpose, but I am not certain how to make a script run at 24 hours after the event is triggered. Any ideas?

What would the script do? If all you want to do is consider the report "true", then when you select from the database, the report is "true" if the timestamp is older than 24 hours and user2 did NOT mark it "false" (reject).

 

If you need something to happen. You can schedule a cron job to run periodically. The cron job would do whatever needs to be done, under the same conditions (timestamp > 24 hours and user2-response != Reject). How frequently you run this cron job depends on how time-critical the "something" is. If you run it every 24 hours, then it will find events anywhere from 24 hours to 47 hours 59 minutes. If you run it every hour, it will find events anywhere from 24 hours to 24 hours 59 minutes. Be sure that the "something" being done includes updating the row to indicate it has been processed.

what kind of system is this for? I can't imagine a whole lot of scenarios where time-based assertions are feasible from a "business" PoV..

A win/loss report for Players in a game.

 

but to answer your question, you'd use a cronjob to run a script every minute or hour or whatever and check the current timestamp(s) in the database vs. current time.

Thanks!

 

What would the script do? If all you want to do is consider the report "true", then when you select from the database, the report is "true" if the timestamp is older than 24 hours and user2 did NOT mark it "false" (reject).

 

If you need something to happen. You can schedule a cron job to run periodically. The cron job would do whatever needs to be done, under the same conditions (timestamp > 24 hours and user2-response != Reject). How frequently you run this cron job depends on how time-critical the "something" is. If you run it every 24 hours, then it will find events anywhere from 24 hours to 47 hours 59 minutes. If you run it every hour, it will find events anywhere from 24 hours to 24 hours 59 minutes. Be sure that the "something" being done includes updating the row to indicate it has been processed.

 

I will have the script do multiple checks, but for the most part your true/reject logic is basically it.

 

I'll dive more into the actual scenario for everyone!

 

A game is played amongst two players.

 

When Player 1 or Player 2 reports the winner, the other player will then have 24 hours to confirm or deny the report.

 

If the other player does not make any report within 24 hours, the winner goes as reported by the first player and the records will be updated.

 

I have these fields on one table:

 

idGame | Player | Winner_report | Winner_report_timestamp | Game_status (1 = In progress, 2 = winner reported, 3 = match confirmed by both players, 4 = match confirmed by reporter, 5 = rejected)

 

an example would be the following:

 

1 | Joe | Joe | 10/15/2013 6:13:13 | 2

1 | Steve | ''| '' | 2

2 | Mary | Mary | 10/15/2013 7:13:13 | 2

2 | Alison | " | '' | 2

 

Steve needs to confirm that Joe was the winner. He has 24 hours to do so or the row will autofill in Joe as the winner and change the status to 4 and Joe will be the winner.

 

 

Would the logic be something like this:

 

Cron job to run every minute to check if 1 row of Game NOT NULL for Winner_report and 1 row of Game IS NULL for Winner_report, then check to see if time is 24 hours past timestamp, and if it is change status to 4 and change records of players based on Winner_report of NOT NULL?

 

Thanks!!

Ryan

Something like that. You don't need a lot of PHP for this, either. You can update ALL of the pending games in a single SQL statement. Something like (untested):

UPDATE playersTable p1 JOIN playersTable p2 ON p1.idGame = p2.idGame
 SET p1.Winner_report = p2.Winner_report, 
	p1.Winner_report_timestamp = NOW(),
	p1.Game_status = 4,
	p2.Game_status = 4
 WHERE p1.Winner_report IS NULL
 AND p2.Winner_report IS NOT NULL
 AND p2.Winner_report_timestamp <= DATE_SUB(NOW(), INTERVAL 24 HOUR)
 

I'm not sure that is the best database design, but not seeing the other tables and not knowing the application, I can't say for sure.

 

You also need to think about a cron job to report (to you) any contested matches. For instance, if Steve comes along and says HE won the game (or maybe you already handle that in the front-end).

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.