فهرست منبع

Merge branch '3.0'

Ask Solem 12 سال پیش
والد
کامیت
feec215a8f
7فایلهای تغییر یافته به همراه30 افزوده شده و 18 حذف شده
  1. 2 1
      CONTRIBUTORS.txt
  2. 22 8
      celery/schedules.py
  3. 0 3
      celery/utils/log.py
  4. 2 2
      celery/utils/threads.py
  5. 2 2
      docs/userguide/canvas.rst
  6. 1 1
      docs/userguide/signals.rst
  7. 1 1
      docs/userguide/tasks.rst

+ 2 - 1
CONTRIBUTORS.txt

@@ -115,4 +115,5 @@ Jed Smith, 2012/07/08
 Rinat Shigapov, 2012/07/20
 Hynek Schlawack, 2012/07/23
 Paul McMillan, 2012/07/26
-Mitar, 2012/07/28
+Mitar, 2012/07/28
+Adam DePue, 2012/08/22

+ 22 - 8
celery/schedules.py

@@ -38,6 +38,7 @@ class ParseException(Exception):
 
 
 class schedule(object):
+    _app = None
     relative = False
 
     def __init__(self, run_every=None, relative=False, nowfun=None):
@@ -46,11 +47,11 @@ class schedule(object):
         self.nowfun = nowfun
 
     def now(self):
-        return (self.nowfun or current_app.now)()
+        return (self.nowfun or self.app.now)()
 
     def remaining_estimate(self, last_run_at):
         return remaining(last_run_at, self.run_every,
-                         self.relative, maybe_make_aware(self.now()))
+                         self.maybe_make_aware(self.now()), self.relative)
 
     def is_due(self, last_run_at):
         """Returns tuple of two items `(is_due, next_time_to_run)`,
@@ -80,12 +81,18 @@ class schedule(object):
             the django-celery database scheduler the value is 5 seconds.
 
         """
+        last_run_at = self.maybe_make_aware(last_run_at)
         rem_delta = self.remaining_estimate(last_run_at)
         rem = timedelta_seconds(rem_delta)
         if rem == 0:
             return True, self.seconds
         return False, rem
 
+    def maybe_make_aware(self, dt):
+        if self.app.conf.CELERY_ENABLE_UTC:
+            return maybe_make_aware(dt)
+        return dt
+
     def __repr__(self):
         return '<freq: {0.human_seconds}>'.format(self)
 
@@ -102,6 +109,16 @@ class schedule(object):
     def human_seconds(self):
         return humanize_seconds(self.seconds)
 
+    @property
+    def app(self):
+        if self._app is None:
+            self._app = current_app._get_current_object()
+        return self._app
+
+    @property
+    def tz(self):
+        return self.app.conf.CELERY_TIMEZONE
+
 
 class crontab_parser(object):
     """Parser for crontab expressions. Any expression of the form 'groups'
@@ -394,7 +411,7 @@ class crontab(schedule):
         self.nowfun = nowfun
 
     def now(self):
-        return (self.nowfun or current_app.now)()
+        return (self.nowfun or self.app.now)()
 
     def __repr__(self):
         return ('<crontab: %s %s %s %s %s (m/h/d/dM/MY)>' %
@@ -414,7 +431,7 @@ class crontab(schedule):
     def remaining_estimate(self, last_run_at, tz=None):
         """Returns when the periodic task should run next as a timedelta."""
         tz = tz or self.tz
-        last_run_at = maybe_make_aware(last_run_at)
+        last_run_at = self.maybe_make_aware(last_run_at)
         dow_num = last_run_at.isoweekday() % 7  # Sunday is day 0, not day 7
 
         execute_this_date = (last_run_at.month in self.month_of_year and
@@ -473,6 +490,7 @@ class crontab(schedule):
         See :meth:`celery.schedules.schedule.is_due` for more information.
 
         """
+        last_run_at = self.maybe_make_aware(last_run_at)
         rem_delta = self.remaining_estimate(last_run_at)
         rem = timedelta_seconds(rem_delta)
         due = rem == 0
@@ -490,10 +508,6 @@ class crontab(schedule):
                     other.minute == self.minute)
         return other is self
 
-    @property
-    def tz(self):
-        return current_app.conf.CELERY_TIMEZONE
-
 
 def maybe_schedule(s, relative=False):
     if isinstance(s, int):

+ 0 - 3
celery/utils/log.py

@@ -193,9 +193,6 @@ class LoggingProxy(object):
         """Always returns :const:`False`. Just here for file support."""
         return False
 
-    def fileno(self):
-        return None
-
 
 def ensure_process_aware_logger():
     """Make sure process name is recorded when loggers are used."""

+ 2 - 2
celery/utils/threads.py

@@ -13,7 +13,7 @@ import sys
 import threading
 import traceback
 
-from kombu.syn import detect_environment
+from kombu.syn import _detect_environment
 
 from celery.local import Proxy
 
@@ -295,7 +295,7 @@ class _FastLocalStack(threading.local):
         except (AttributeError, IndexError):
             return None
 
-if detect_environment() == 'default' and not USE_PURE_LOCALS:
+if _detect_environment() == 'default' and not USE_PURE_LOCALS:
     LocalStack = _FastLocalStack
 else:
     # - See #706

+ 2 - 2
docs/userguide/canvas.rst

@@ -31,8 +31,8 @@ or even serialized and sent across the wire.
         >>> subtask('tasks.add', args=(2, 2), countdown=10)
         tasks.add(2, 2)
 
-    This subtask has a signature of arity 2 (two arguments): ``(2, 2)``,
-    and sets the countdown execution option to 10.
+  This subtask has a signature of arity 2 (two arguments): ``(2, 2)``,
+  and sets the countdown execution option to 10.
 
 - or you can create one using the task's ``subtask`` method::
 

+ 1 - 1
docs/userguide/signals.rst

@@ -41,7 +41,7 @@ has been sent by providing the `sender` argument to
 
 .. code-block:: python
 
-    @task_sent.connect(task_sent_handler, sender='tasks.add')
+    @task_sent.connect(sender='tasks.add')
     def task_sent_handler(sender=None, task_id=None, task=None, args=None,
                           kwargs=None, \*\*kwds):
         print('Got signal task_sent for task id {0}'.format(task_id)

+ 1 - 1
docs/userguide/tasks.rst

@@ -836,7 +836,7 @@ that can be added to tasks like this:
 
     @celery.task(base=DatabaseTask)
     def process_rows():
-        for row in self.db.table.all():
+        for row in process_rows.db.table.all():
             ...
 
 The ``db`` attribute of the ``process_rows`` task will then