core: poll the task queue by date, oldest task first.

(cherry picked from commit d396f406710120bfb9f22078fd9314056f1c79d6)