Commits

Max Arnold committed e3928fd

Fixed nasty bug and refactored wayback method

  • Participants
  • Parent commits 2cedf16

Comments (0)

Files changed (1)

         # Do something with task history!
         pass
 
-    def wayback(self, wbtime=86400, tnow=None):
+    def wayback(self, jobs=None, wbtime=86400, tnow=None, stopfirst=True):
         """Look back in time (wbtime seconds maximum) and find last matching jobs
 
         Useful right after instantiation if previous task should be executed again.
         """
         wbtasks = set()
         if tnow is None: tnow = int(time.mktime(datetime.today().timetuple()))
-        for j in self.jobs:
+        if jobs == None: jobs = self.jobs
+
+        if stopfirst:
             for ts in xrange(tnow, tnow-wbtime-1, -1):
-                if pycron.match_job(j[0], ts):
-                    wbtasks.add((j[1], ts))
-                    break
+                for j in jobs:
+                    if pycron.match_job(j[0], ts):
+                        return tuple((j[1],))
+            return tuple()
+        else:
+            for j in jobs:
+                for ts in xrange(tnow, tnow-wbtime-1, -1):
+                    if pycron.match_job(j[0], ts):
+                        wbtasks.add((j[1], ts))
+                        break
 
-        return tuple([t[0] for t in sorted(wbtasks, key=itemgetter(1, 0))])
+        return tuple([t[0] for t in sorted(wbtasks, key=itemgetter(1), reverse=True)])
 
     def get_matched_jobs(self, tnow=None):
         """Return tuple of matched task identifiers
             self.purge_taskhist(tnow)
 
         self.tlast = tnow
-        return tuple([t[0] for t in sorted(tasks, key=itemgetter(1, 0))])
+        return tuple([t[0] for t in sorted(tasks, key=itemgetter(1))])
 
     def clear_taskhist(self):
         self.taskhist = set()