コード例 #1
0
ファイル: models.py プロジェクト: dcollinsn/django-async
    def execute(self, **_meta):
        """
            Run the job using the specified meta values to control the
            execution.
        """
        try:
            try:
                _logger.info("%s %s", self.id, unicode(self))
            except NameError:
                _logger.info("%s %s", self.id, str(self))
            args = loads(self.args)
            kwargs = non_unicode_kwarg_keys(loads(self.kwargs))
            function = object_at_end_of_path(self.name)
            _logger.debug(u"%s resolved to %s" % (self.name, function))

            def execute():
                """Execute the database updates in one transaction.
                """
                self.started = timezone.now()
                result = function(*args, **kwargs)
                self.executed = timezone.now()
                self.cancelled = None
                self.result = dumps(result)
                self.save()
                return result

            return atomic(execute)()
        except Exception as exception:
            self.started = None
            errors = 1 + self.errors.count()
            self.scheduled = (timezone.now() +
                              timedelta(seconds=60 * pow(errors, 1.6)))
            self.priority = self.priority - 1
            _logger.error(
                "Job failed. Rescheduled for %s after %s error(s). "
                "New priority is %s", self.scheduled, errors, self.priority)

            def record():
                """Local function allows us to wrap these updates into a
                transaction.
                """
                Error.objects.create(job=self,
                                     exception=repr(exception),
                                     traceback=format_exc())
                self.save()

            atomic(record)()
            raise
コード例 #2
0
ファイル: models.py プロジェクト: jainpawan/django-async
 def execute(self, **_meta):
     """
         Run the job using the specified meta values to control the
         execution.
     """
     try:
         _logger.info("%s %s", self.id, unicode(self))
         args = loads(self.args)
         kwargs = non_unicode_kwarg_keys(loads(self.kwargs))
         #Add priority and fairness to kwargs.
         kwargs['priority'] = self.priority
         kwargs['fairness'] = self.fairness
         function = object_at_end_of_path(self.name)
         _logger.debug(u"%s resolved to %s" % (self.name, function))
         def execute():
             """Execute the database updates in one transaction.
             """
             self.started = timezone.now()
             result = function(*args, **kwargs)
             self.executed = timezone.now()
             self.result = dumps(result)
             self.save()
             return result
         return transaction.commit_on_success(execute)()
     except Exception, exception:
         self.started = None
         errors = 1 + self.errors.count()
         self.scheduled = (timezone.now() +
             timedelta(seconds=60 * pow(errors, 1.6)))
         self.priority = self.priority - 1
         _logger.error(
             "Job %s failed. Rescheduled for %s after %s error(s). "
                 "New priority is %s."
                 "Exception is %s."
                 "Trace is %s",
             self.id, self.scheduled, errors, self.priority, repr(exception), format_exc())
         def record():
             """Local function allows us to wrap these updates into a
             transaction.
             """
             Error.objects.create(job=self, exception=repr(exception),
                 traceback=format_exc())
             self.save()
         transaction.commit_on_success(record)()
         raise
コード例 #3
0
ファイル: models.py プロジェクト: hdzierz/django-async
 def execute(self, **_meta):
     """
         Run the job using the specified meta values to control the
         execution.
     """
     def start():
         """Record the start time for the job.
         """
         self.started = datetime.now()
         self.save()
     transaction.commit_on_success(start)()
     try:
         _logger.info("%s %s", self.id, unicode(self))
         args = loads(self.args)
         kwargs = non_unicode_kwarg_keys(loads(self.kwargs))
         function = object_at_end_of_path(self.name)
         _logger.debug(u"%s resolved to %s" % (self.name, function))
         result = transaction.commit_on_success(function)(*args, **kwargs)
     except Exception as exception:
         self.started = None
         errors = 1 + self.errors.count()
         self.scheduled = (datetime.now() +
             timedelta(seconds=60 * pow(errors, 1.6)))
         self.priority = self.priority - 1
         _logger.error(
             "Job failed. Rescheduled for %s after %s error(s). "
                 "New priority is %s",
             self.scheduled, errors, self.priority)
         def record():
             """Local function allows us to wrap these updates into a
             transaction.
             """
             Error.objects.create(job=self, exception=repr(exception),
                 traceback=format_exc())
             self.save()
         transaction.commit_on_success(record)()
         raise
     else:
         self.executed = datetime.now()
         self.result = dumps(result)
         self.save() # Single SQL statement so no need for transaction
         return result
コード例 #4
0
ファイル: models.py プロジェクト: numegil/django-async
 def execute(self, **_meta):
     """
         Run the job using the specified meta values to control the
         execution.
     """
     def start():
         """Record the start time for the job.
         """
         self.started = datetime.now()
         self.save()
     transaction.commit_on_success(start)()
     try:
         _logger.info("%s %s", self.id, unicode(self))
         args = loads(self.args)
         kwargs = non_unicode_kwarg_keys(loads(self.kwargs))
         function = object_at_end_of_path(self.name)
         _logger.debug(u"%s resolved to %s" % (self.name, function))
         result = transaction.commit_on_success(function)(*args, **kwargs)
     except Exception, exception:
         self.started = None
         errors = 1 + self.errors.count()
         self.scheduled = (datetime.now() +
             timedelta(seconds=60 * pow(errors, 1.6)))
         self.priority = self.priority - 1
         _logger.error(
             "Job failed. Rescheduled for %s after %s error(s). "
                 "New priority is %s",
             self.scheduled, errors, self.priority)
         def record():
             """Local function allows us to wrap these updates into a
             transaction.
             """
             Error.objects.create(job=self, exception=repr(exception),
                 traceback=format_exc())
             self.save()
         transaction.commit_on_success(record)()
         raise
コード例 #5
0
ファイル: models.py プロジェクト: pbrooks/django-async
 def execute(self, **_meta):
     """
         Run the job using the specified meta values to control the
         execution.
     """
     try:
         _logger.info("%s %s", self.id, unicode(self))
         args = loads(self.args)
         kwargs = non_unicode_kwarg_keys(loads(self.kwargs))
         function = object_at_end_of_path(self.name)
         _logger.debug(u"%s resolved to %s" % (self.name, function))
         result = transaction.commit_on_success(function)(*args, **kwargs)
     except Exception, exception:
         self.scheduled = (timezone.now() +
             timedelta(seconds=4 ** (1 + self.errors.count())))
         def record():
             """Local function allows us to wrap these updates into a
             transaction.
             """
             Error.objects.create(job=self, exception=repr(exception),
                 traceback=format_exc())
             self.save()
         transaction.commit_on_success(record)()
         raise
コード例 #6
0
ファイル: models.py プロジェクト: pombredanne/django-async
 def execute(self, **_meta):
     """
         Run the job using the specified meta values to control the
         execution.
     """
     try:
         _logger.info("%s %s", self.id, unicode(self))
         args = loads(self.args)
         kwargs = non_unicode_kwarg_keys(loads(self.kwargs))
         function = object_at_end_of_path(self.name)
         _logger.debug(u"%s resolved to %s" % (self.name, function))
         result = transaction.commit_on_success(function)(*args, **kwargs)
     except Exception, exception:
         self.scheduled = (datetime.now() +
             timedelta(seconds=4 ** (1 + self.errors.count())))
         def record():
             """Local function allows us to wrap these updates into a
             transaction.
             """
             Error.objects.create(job=self, exception=repr(exception),
                 traceback=format_exc())
             self.save()
         transaction.commit_on_success(record)()
         raise