Esempio n. 1
0
    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
Esempio n. 2
0
 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
Esempio n. 3
0
 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
Esempio n. 4
0
 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
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 7
0
 def test_with_global(self):
     """Make sure we can access a builtin
     """
     found = object_at_end_of_path('list')
     self.assertEqual(found, list)
Esempio n. 8
0
 def test_with_global(self):
     """Make sure we can access a builtin
     """
     found = object_at_end_of_path('list')
     self.assertEqual(found, list)