From 1962c1759f49b75ddf863391f3734ae03463da27 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Thu, 4 Jan 2018 10:51:37 +0800 Subject: [PATCH] Sort pending tasks in correct order --- eos/core/tasks/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eos/core/tasks/__init__.py b/eos/core/tasks/__init__.py index 91e9623..96cb0ea 100644 --- a/eos/core/tasks/__init__.py +++ b/eos/core/tasks/__init__.py @@ -69,6 +69,9 @@ class TaskScheduler: if task.status == Task.Status.READY: pending_tasks.append(task) + # Sort them to ensure we iterate over them in the correct order + pending_tasks.sort(key=lambda task: task.run_at.timestamp() if task.run_at else 0) + return pending_tasks @staticmethod