Author Topic: Cron OR "update what user see" on Manager game  (Read 530 times)

Offline saljutin

  • Level 22
  • *
  • Posts: 266
  • Reputation: +6/-0
    • View Profile
Cron OR "update what user see" on Manager game
« on: May 30, 2011, 10:17:34 AM »
Hello

lets say you are making manager type game:
- clubs
- matches (2 times per week or something - FIX hour!)
- tournaments (tournament table changes when matches are played, A pts for win, 0 pts for loose, B pts for draw)
- weekly update (finances from sponsors, stamina update)

would you go with CRON or "update what user see" type?

lets say you go with "update what user see"...
on wednesday there is game
on sunday there is stamina update
user A logins on Wednesday after game is played - so you need to update MATCH, TOURNAMENT TABLE...and now problem - you need to simulate several matches where users DID NOT loggin after sunday and before wednesday to make sure their players stamina got updated

would you go with cron?
lets say you make some global table with time_last_updated - where you hold time from last sunday..so you check if time difference between now and last update is >=7 days and UPDATE all...or go with cron?

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Cron OR "update what user see" on Manager game
« Reply #1 on: May 30, 2011, 12:41:14 PM »
No brainer in this case, use cron. I can't even think how could you make it other way (without making very very complex code).

If you are paranoid, you can make the matches at different times (fist 1,000 matches at 8:00, next 1,000 at 8:30 and so on).

Offline footyfish

  • Level 2
  • *
  • Posts: 3
  • Reputation: +0/-0
    • View Profile
Re: Cron OR "update what user see" on Manager game
« Reply #2 on: May 30, 2011, 12:53:34 PM »
For footysquad I do it slightly differently, i have queues for updating so push them when i can and not all at once. I also keep multiple turns in the database at once. More complex solution, but scales much better.

edit: come to #bbg on irc.freenode.net if u want more info.

Offline girasquid

  • Level 3
  • *
  • Posts: 7
  • Reputation: +1/-0
    • View Profile
Re: Cron OR "update what user see" on Manager game
« Reply #3 on: May 30, 2011, 01:17:52 PM »
Avoid using cron for this - you're going to be doing unnecessary processing when you don't need to do anything (wasting $$ for CPU time), and you're opening yourself up to race conditions and maintenance hassle if the amount of things you have to process and the time to process them ever creeps outside of the period of your cronjob.

If it's too complex to handle only updating things directly linked to the player, I'd recommend just timestamping and processing *everything*, like this:
Code: [Select]
events_to_process = `SELECT event WHERE process_timestamp <= NOW()`
for event in events_to_process:
  process_event(event)

Offline saljutin

  • Level 22
  • *
  • Posts: 266
  • Reputation: +6/-0
    • View Profile
Re: Cron OR "update what user see" on Manager game
« Reply #4 on: May 30, 2011, 02:08:20 PM »
not sure if I understand this whole process timestamp thingy
you write in some table all unprocessed matches etc?

Offline girasquid

  • Level 3
  • *
  • Posts: 7
  • Reputation: +1/-0
    • View Profile
Re: Cron OR "update what user see" on Manager game
« Reply #5 on: May 31, 2011, 10:30:50 AM »
Not quite - you'd still use the exact same table, you'd just have an extra column to track when they were supposed to be processed (so that it'd be easy to retrieve events for a player, and also unprocessed events for a player).

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal