Commits

Lynn Rees  committed 124bb85

- add settings fetcher

  • Participants
  • Parent commits ff4a0e8

Comments (0)

Files changed (6)

File .settings/org.eclipse.core.resources.prefs

-#Thu Oct 06 20:53:18 MDT 2011
+#Sat Oct 08 09:05:04 MDT 2011
 eclipse.preferences.version=1
 encoding//django_ztask/decorators.py=utf-8
 encoding//django_ztask/management/__init__.py=utf-8
 encoding//django_ztask/migrations/0002_auto__add_field_task_created.py=utf-8
 encoding//django_ztask/models.py=utf-8
+encoding//django_ztask/utils.py=utf-8

File django_ztask/__init__.py

 
 import os
 
-VERSION = (0, 1, 6)
+VERSION = (0, 1, 7)
 
 __version__ = '.'.join(map(str, VERSION[0:3])) + ''.join(VERSION[3:])
 __author__ = 'Jason Allum and Dave Martorana'

File django_ztask/conf/__init__.py

Empty file removed.

File django_ztask/conf/settings.py

-
-
-from django.conf import settings
-
-

File django_ztask/decorators.py

 import types
 from functools import wraps
 
-from django.conf import settings
 from django.utils.log import getLogger
+from django_ztask.utils import setting
 
 try:
     from zmq import PUSH
 
 from django_ztask.context import shared_context as context
     
-log = getLogger(getattr(settings, 'ZTASKD_LOGGER', 'django_ztaskd'))
+log = getLogger(setting('ZTASKD_LOGGER', 'django_ztaskd'))
 
 def task():
     def wrapper(func):
         function_name = '%s.%s' % (func.__module__, func.__name__)
         log.info('Registered task: %s' % function_name)
         socket = context.socket(PUSH)
-        socket.connect(getattr(settings, 'ZTASKD_URL', 'tcp://127.0.0.1:5555'))
+        socket.connect(setting('ZTASKD_URL', 'tcp://127.0.0.1:5555'))
         
         @wraps(func)
         def _func(*args, **kw):
             after = kw.pop('__ztask_after', 0)
-            if getattr(settings, 'ZTASKD_DISABLED', False):
+            if setting('ZTASKD_DISABLED', False):
                 try:
                     socket.send_pyobj(('ztask_log', (
                         'Would have called but ZTASKD_DISABLED is True', 
                         'True' % function_name
                     )
                 return
-            elif getattr(settings, 'ZTASKD_ALWAYS_EAGER', False):
+            elif setting('ZTASKD_ALWAYS_EAGER', False):
                 log.info(
                     'Running %s in ZTASKD_ALWAYS_EAGER mode' % function_name
                 )

File django_ztask/management/commands/ztaskd.py

 import datetime
 from optparse import make_option
 
-from django.conf import settings
 from django.utils.log import getLogger
 from django.utils import autoreload, importlib
 from django.core.management.base import BaseCommand
 from zmq.eventloop import ioloop
 
 from django_ztask.models import Task
+from django_ztask.utils import setting 
 from django_ztask.context import shared_context as context
 
-log = getLogger(getattr(settings, 'ZTASKD_LOGGER', 'django_ztaskd'))
+log = getLogger(setting('ZTASKD_LOGGER', 'django_ztaskd'))
 
  
 class Command(BaseCommand):
             self._handle(use_reloader, replay_failed)
     
     def _handle(self, use_reloader, replay_failed):
-        ztask_url = getattr(settings, 'ZTASKD_URL', 'tcp://127.0.0.1:5555')
+        ztask_url = setting('ZTASKD_URL', 'tcp://127.0.0.1:5555')
         log.info("%sServer starting on %s." % (
             'Development ' if use_reloader else '', ztask_url)
         )
                     function_name=function_name, 
                     args=pickle.dumps(args), 
                     kwargs=pickle.dumps(kw), 
-                    retry_count=getattr(settings, 'ZTASKD_RETRY_COUNT', 5),
+                    retry_count=setting('ZTASKD_RETRY_COUNT', 5),
                     next_attempt=time.time() + after
                 )
                 if after:
         except Exception, e:
             log.exception('Error calling %s' % function_name)
             try:
-                retry_count = getattr(settings, 'ZTASKD_RETRY_COUNT', 5)
+                retry_count = setting('ZTASKD_RETRY_COUNT', 5)
                 task = Task.objects.get(pk=task_id)
                 if task.retry_count > 0:
                     task.retry_count = task.retry_count - 1
                 log.exception('Error capturing exception in _call_function')
         
     def _on_load(self):
-        ztaskd_on_load = getattr(settings, 'ZTASKD_ON_LOAD', ())
+        ztaskd_on_load = setting('ZTASKD_ON_LOAD', ())
         for callable_name in ztaskd_on_load:
             log.info("ON_LOAD calling %s" % callable_name)
             parts = callable_name.split('.')