SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Small Error Gap But 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
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Timestamp? Store a timestamp for when user last did a task?
    With a timestamp you can check individually instead of by cron?

    If a timestamp cant do, why not tell the script the cron job has started, and as such the task is not yet available? Set a flag in a file, or DB.

    You are a bit vague... The above is just fishing for a solution.

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    I'd run this slightly different so that you don't need a cron job, just a query to check progress for whenever you feel like it.

    tbl_tasks
    ----
    whatever your current setup is
    task_id*

    tbl_task_completions
    ----
    task_id
    user_id
    task_completion TIMESTAMP

    on the server side in php, ensure that multiples are done for the same day before insertion into completions, this will allow the user to work ahead if you / they want to without a cron running.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •