Browse Source

Merge branch 'master' of github.com:ask/celery

Ask Solem 15 years ago
parent
commit
0b48fe05cb
3 changed files with 36 additions and 4 deletions
  1. 4 4
      celery/task/schedules.py
  2. 24 0
      celery/tests/test_task.py
  3. 8 0
      celery/utils/__init__.py

+ 4 - 4
celery/task/schedules.py

@@ -1,7 +1,7 @@
 from datetime import datetime
-from collections import Iterable
 from pyparsing import Word, Literal, ZeroOrMore, Optional, Group, StringEnd, alphas
 
+from celery.utils import is_iterable
 from celery.utils.timeutils import timedelta_seconds, weekday, remaining
 
 
@@ -185,11 +185,11 @@ class crontab(schedule):
             result = crontab_parser(max_).parse(cronspec)
         elif isinstance(cronspec, set):
             result = cronspec
-        elif isinstance(cronspec, Iterable):
+        elif is_iterable(cronspec):
             result = set(cronspec)
         else:
             raise TypeError("Argument cronspec needs to be of any of the " + \
-                    "following types: int, basestring, set, or Iterable. " + \
+                    "following types: int, basestring, or an iterable type. " + \
                     "'%s' was given." % type(cronspec))
 
         # assure the result does not exceed the max
@@ -217,7 +217,7 @@ class crontab(schedule):
         last = now - last_run_at
         due, when = False, 1
         if last.days > 0 or last.seconds > 60:
-            due = now.isoweekday() in self.day_of_week and \
+            due = now.isoweekday() % 7 in self.day_of_week and \
                   now.hour in self.hour and \
                   now.minute in self.minute
         return due, when

+ 24 - 0
celery/tests/test_task.py

@@ -636,6 +636,30 @@ class test_crontab_is_due(unittest.TestCase):
         self.assertFalse(due)
         self.assertEquals(remaining, 1)
 
+    # 29th of May 2010 is a saturday
+    @patch_crontab_nowfun(HourlyPeriodic, datetime(2010, 5, 29, 10, 30))
+    def test_execution_is_due_on_saturday(self):
+        last_ran = datetime.now() - timedelta(seconds=61)
+        due, remaining = EveryMinutePeriodic().is_due(last_ran)
+        self.assertTrue(due)
+        self.assertEquals(remaining, 1)
+
+    # 30th of May 2010 is a sunday
+    @patch_crontab_nowfun(HourlyPeriodic, datetime(2010, 5, 30, 10, 30))
+    def test_execution_is_due_on_sunday(self):
+        last_ran = datetime.now() - timedelta(seconds=61)
+        due, remaining = EveryMinutePeriodic().is_due(last_ran)
+        self.assertTrue(due)
+        self.assertEquals(remaining, 1)
+
+    # 31st of May 2010 is a monday
+    @patch_crontab_nowfun(HourlyPeriodic, datetime(2010, 5, 31, 10, 30))
+    def test_execution_is_due_on_monday(self):
+        last_ran = datetime.now() - timedelta(seconds=61)
+        due, remaining = EveryMinutePeriodic().is_due(last_ran)
+        self.assertTrue(due)
+        self.assertEquals(remaining, 1)
+
     @patch_crontab_nowfun(HourlyPeriodic, datetime(2010, 5, 10, 10, 30))
     def test_every_hour_execution_is_due(self):
         due, remaining = HourlyPeriodic().is_due(datetime(2010, 5, 10, 6, 30))

+ 8 - 0
celery/utils/__init__.py

@@ -90,6 +90,14 @@ def padlist(container, size, default=None):
     return list(container)[:size] + [default] * (size - len(container))
 
 
+def is_iterable(obj):
+    try:
+        iter(obj)
+    except TypeError:
+        return False
+    return True
+
+
 def mitemgetter(*items):
     """Like :func:`operator.itemgetter` but returns ``None`` on missing items
     instead of raising :exc:`KeyError`."""