The first thing should compute the minutes left to finish the task. I think you could fix it by using while {$t_total_mins ..., but this is a rough guess from briefly looking at the code.
Can you be a little bit specific on tasks not showing up? The tasks-postgresl.xql has been significantly tuned for performance and if we lost some tasks on the way it is mandatory for us to find out where.