Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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