#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    202
    Rep Power
    4

    Small Error Gap Which Is Big


    Hi, my site requires users to complete a certain task on the site everyday before the end of the day 23:59:59 (don't worry about timezones or the task)

    The task has a $today_status (complete or incomplete)

    I have a cron that runs at the start of the day (00:00:01) to do 2 things:

    01 - check if all tasks were completed yesterday (check for all tasks that are still incomplete)
    02 - reset all of yesterdays tasks back to incomplete so the user can start the task again today (for the new day)

    Each task has a count down timer displayed next to it so that the user can see one of the following two timers:

    A (IF $today_status = incomplete) - the time they have left to complete the task (counting down to the end of the day)
    B (IF $today_status = complete) - the time they have to wait before they can complete the second task (counting down to the end of the day)

    I have 2 small problems that are related:

    The crons runs as soon as it turns into a new day at 00:00:01 however the cron not might finish processing all of the tasks until 00:07:19 so there is a 7 min error gap... this could increase as more users join.

    So, if the user has completed the task for the previous day, and then views the task at 00:03:27 the next day... $today_status could still be 'completed' as the cron might not have processed it for the previous day yet... and there for the timer will say

    23:54:33
    (time left to wait before you can start the next task)

    It will say the above because it is still in 'complete' status... however the user just logged in early so they could complete today's task early BUT the site is telling them otherwise... it is telling them they have to wait until tomorrow to complete the next task...

    I hope i am explaining this correctly and thank you so much if you have bothered to read down this far... any help will be greatly appreciated... thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,618
    Rep Power
    595
    OK, so what does any of this have to do with PHP?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    202
    Rep Power
    4
    Thank you for reading...

    To answer your question... hopefully someone who programs in PHP can advise on a better solution or fix... in "PHP"
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Store the most recent timestamp the task was complete. That way your code can know if "today's" task was actually completed today, since you'll have the timestamp of that user's task to compare to the current time.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,618
    Rep Power
    595
    I see no PHP to fix or advise. However, I can give you a general suggestion. When the cron job starts set a flag somewhere that your page can read. If set have your page output a notice, rather than task data, indicating the data is being updated and to please try later. Once the cron job finishes clear that flag.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    I can only think of a workaround. As the cron will be more and more slow, then you could add a "last_cron_date" field that will show you when have the cron last time fixed the given task. Thus in the UI you will check if the task has been passed by the cron TODAY, and if so display the remaininng. If the cron has not yet reached this task, its date field will still be yesterday, and you can handle this properly - either say "this task is being currently handled", or allow it to be handled or whatever you decide to do for the handling time gap.
    Last edited by requinix; December 7th, 2012 at 02:09 AM. Reason: removed spam

IMN logo majestic logo threadwatch logo seochat tools logo