Beispiel #1
0
    def is_due(self, last_run_at, now = None):
        """Returns tuple of two items ``(is_due, next_time_to_run)``,
        where next time to run is in seconds.

        See :meth:`unuk.contrib.tasks.models.PeriodicTask.is_due` for more information.
        """
        rem_delta = self.remaining_estimate(last_run_at, now = now)
        rem = timedelta_seconds(rem_delta)
        if rem == 0:
            return True, timedelta_seconds(self.run_every)
        return False, rem
Beispiel #2
0
 def scheduled_last_run_at(self):
     '''The scheduled last run datetime. This is different from :attr:`last_run_at` only when :attr:`anchor` is set.'''
     last_run_at = self.last_run_at
     anchor = self.anchor
     if last_run_at and anchor:
         run_every = self.run_every
         times = int(timedelta_seconds(last_run_at - anchor)/timedelta_seconds(run_every))
         if times:
             anchor += times*run_every
             while anchor <= last_run_at:
                 anchor += run_every
             while anchor > last_run_at:
                 anchor -= run_every
             self.schedule.anchor = anchor
         return anchor
     else:
         return last_run_at
Beispiel #3
0
 def _testAnchored(self, entry, delta):
     # First test is_due is False
     last_run_at = entry.scheduled_last_run_at
     now = last_run_at + delta 
     is_due, next_time_to_run = entry.is_due(now = now)
     self.assertFalse(is_due)
     next_run_at = last_run_at + entry.run_every
     seconds = timedelta_seconds(next_run_at - now)
     self.assertAlmostEqual(next_time_to_run,seconds,2)
     
     # Second test is_due is True
     now = next_run_at
     is_due, next_time_to_run = entry.is_due(now = now)
     self.assertTrue(is_due)
     self.assertEqual(next_time_to_run,timedelta_seconds(entry.run_every))
     
     # check the new entry
     new_entry = entry.next(now = now)
     self.assertEqual(new_entry.scheduled_last_run_at,last_run_at + entry.run_every)