Commits

Max Arnold  committed 39c4f69

Sort returned task list by time

  • Participants
  • Parent commits bec1f13

Comments (0)

Files changed (1)

 import re
 import time
 from datetime import datetime
+from operator import itemgetter
 
 class pycron(object):
     """Main cron class
                 th = (j[0], j[1], tnow)
                 if pycron.match_job(j[0], tnow):
                     self.taskhist.add(th)
-                    tasks.add(j[1])
+                    tasks.add((j[1], tnow))
         else:
             # time jumped back or forward, but still within latency window
             self.purge_taskhist(tnow)
                     th = (j[0], j[1], ts)
                     if pycron.match_job(j[0], ts) and th not in self.taskhist:
                         self.taskhist.add(th)
-                        tasks.add(j[1])
+                        tasks.add((j[1], ts))
 
         self.tlast = tnow
-        return tuple(sorted(tasks))
+        return tuple([t[0] for t in sorted(tasks, key=itemgetter(1, 0))])
 
     def clear_taskhist(self):
         self.taskhist = set()
                 and t.month in r[4] and t.isoweekday() in r[5]:
             return True
         return False
+
+if __name__ == '__main__':
+    c = pycron()
+    c.add_job('*/5 * * * * *', 'job_id1', 'job_info1')
+    while True:
+        time.sleep(1)
+        print datetime.today(), c.get_matched_jobs()