Browse Source

Merge branch '3.0'

Conflicts:
	celery/contrib/rdb.py
	celery/platforms.py
Ask Solem 12 years ago
parent
commit
70bbadc0e4
4 changed files with 50 additions and 22 deletions
  1. 1 0
      celery/beat.py
  2. 13 12
      celery/schedules.py
  3. 25 7
      celery/states.py
  4. 11 3
      celery/utils/timeutils.py

+ 1 - 0
celery/beat.py

@@ -7,6 +7,7 @@
 
 """
 from __future__ import absolute_import
+from __future__ import with_statement
 
 import errno
 import os

+ 13 - 12
celery/schedules.py

@@ -35,7 +35,7 @@ int, basestring, or an iterable type. {type!r} was given.\
 """
 
 
-def weak_bool(s):
+def _weak_bool(s):
     return 0 if s == '0' else s
 
 
@@ -126,10 +126,10 @@ class schedule(object):
     def utc_enabled(self):
         return self.app.conf.CELERY_ENABLE_UTC
 
-    @cached_property
-    def to_local(self):
-        return (timezone.to_local if self.utc_enabled
-                                  else timezone.to_local_fallback)
+    def to_local(self, dt):
+        if not self.utc_enabled:
+            return timezone.to_local_fallback(dt, self.tz)
+        return dt
 
 
 class crontab_parser(object):
@@ -427,11 +427,11 @@ class crontab(schedule):
 
     def __repr__(self):
         return ('<crontab: %s %s %s %s %s (m/h/d/dM/MY)>' %
-                        (weak_bool(self._orig_minute) or '*',
-                         weak_bool(self._orig_hour) or '*',
-                         weak_bool(self._orig_day_of_week) or '*',
-                         weak_bool(self._orig_day_of_month) or '*',
-                         weak_bool(self._orig_month_of_year) or '*'))
+                        (_weak_bool(self._orig_minute) or '*',
+                         _weak_bool(self._orig_hour) or '*',
+                         _weak_bool(self._orig_day_of_week) or '*',
+                         _weak_bool(self._orig_day_of_month) or '*',
+                         _weak_bool(self._orig_month_of_year) or '*'))
 
     def __reduce__(self):
         return (self.__class__, (self._orig_minute,
@@ -492,8 +492,9 @@ class crontab(schedule):
                     delta = self._delta_to_next(last_run_at,
                                                 next_hour, next_minute)
 
-        return remaining(self.to_local(last_run_at, tz),
-                         delta, self.to_local(self.now(), tz))
+        now = self.maybe_make_aware(self.now())
+        return remaining(self.to_local(last_run_at), delta,
+                         self.to_local(now))
 
     def is_due(self, last_run_at):
         """Returns tuple of two items `(is_due, next_time_to_run)`,

+ 25 - 7
celery/states.py

@@ -3,7 +3,7 @@
 celery.states
 =============
 
-Built-in Task States.
+Built-in task states.
 
 .. _states:
 
@@ -12,6 +12,8 @@ States
 
 See :ref:`task-states`.
 
+.. _statesets:
+
 Sets
 ----
 
@@ -84,22 +86,38 @@ def precedence(state):
 
 class state(str):
     """State is a subclass of :class:`str`, implementing comparison
-    methods adhering to state precedence rules."""
+    methods adhering to state precedence rules::
+
+        >>> from celery.states import state, PENDING, SUCCESS
+
+        >>> state(PENDING) < state(SUCCESS)
+        True
+
+    Any custom state is considered to be lower than :state:`FAILURE` and
+    :state:`SUCCESS`, but higher than any of the other built-in states::
+
+        >>> state('PROGRESS') > state(STARTED)
+        True
+
+        >>> state('PROGRESS') > state('SUCCESS')
+        False
+
+    """
 
-    def compare(self, other, fun, default=False):
+    def compare(self, other, fun):
         return fun(precedence(self), precedence(other))
 
     def __gt__(self, other):
-        return self.compare(other, lambda a, b: a < b, True)
+        return self.compare(other, lambda a, b: a < b)
 
     def __ge__(self, other):
-        return self.compare(other, lambda a, b: a <= b, True)
+        return self.compare(other, lambda a, b: a <= b)
 
     def __lt__(self, other):
-        return self.compare(other, lambda a, b: a > b, False)
+        return self.compare(other, lambda a, b: a > b)
 
     def __le__(self, other):
-        return self.compare(other, lambda a, b: a >= b, False)
+        return self.compare(other, lambda a, b: a >= b)
 
 #: Task state is unknown (assumed pending since you know the id).
 PENDING = 'PENDING'

+ 11 - 3
celery/utils/timeutils.py

@@ -8,6 +8,7 @@
 """
 from __future__ import absolute_import
 
+import os
 import time as _time
 from itertools import izip
 
@@ -27,6 +28,9 @@ except ImportError:     # pragma: no cover
     pytz = None         # noqa
 
 
+C_REMDEBUG = os.environ.get('C_REMDEBUG', False)
+
+
 DAYNAMES = 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'
 WEEKDAYS = dict(izip(DAYNAMES, range(7)))
 
@@ -129,7 +133,7 @@ class _Zone(object):
 
     @cached_property
     def local(self):
-        return tz.tzlocal()
+        return _get_local_timezone()
 
     @cached_property
     def utc(self):
@@ -189,7 +193,7 @@ def delta_resolution(dt, delta):
     return dt
 
 
-def remaining(start, ends_in, now=None, relative=False):
+def remaining(start, ends_in, now=None, relative=False, debug=False):
     """Calculate the remaining time for a start date and a timedelta.
 
     e.g. "how many seconds left for 30 seconds after start?"
@@ -207,7 +211,11 @@ def remaining(start, ends_in, now=None, relative=False):
     end_date = start + ends_in
     if relative:
         end_date = delta_resolution(end_date, ends_in)
-    return end_date - now
+    ret = end_date - now
+    if C_REMDEBUG:
+        print('rem: NOW:%s START:%s END_DATE:%s REM:%s' % (
+            now, start, end_date, ret))
+    return ret
 
 
 def rate(rate):