1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Small Error Gap But Big

Discussion in 'PHP' started by oo7ml, Dec 6, 2012.

  1. #1
    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

    (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
    oo7ml, Dec 6, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    You're explaining it correctly but not sufficiently.

    When the cron job starts running, can the task immediately be run for the new day? Or does the user actually have to wait until the cron job finishes before the work is done that needs to be done for the task to be usable again?

    If the former, just break the cron job into 2 jobs - run the first, setting the status to incomplete, then run the rest of the job as a second job.

    If it actually takes 7 minutes to do what's needed before the user can do the task, he just has to wait until the cron job completes (or you invent a time compressor).

    This isn't a computer programming problem, it's a workflow problem. If a job takes X minutes to complete it can't be complete in less than X minutes. That's what "takes X minutes to complete" means.
    Rukbat, Dec 6, 2012 IP