marnold avatar marnold committed e3928fd

Fixed nasty bug and refactored wayback method

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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.