Ejemplo n.º 1
0
    def _callback(self, cr, uid, model_name, method_name, args, job_id):
        """ Run the method associated to a given job

        It takes care of logging and exception handling.

        :param model_name: model name on which the job method is located.
        :param method_name: name of the method to call when this job is processed.
        :param args: arguments of the method (without the usual self, cr, uid).
        :param job_id: job id.
        """
        args = str2tuple(args)
        model = self.pool.get(model_name)
        if model and hasattr(model, method_name):
            method = getattr(model, method_name)
            try:
                log_depth = None if _logger.isEnabledFor(logging.DEBUG) else 1
                netsvc.log(
                    _logger,
                    logging.DEBUG,
                    "cron.object.execute",
                    (cr.dbname, uid, "*", model_name, method_name) + tuple(args),
                    depth=log_depth,
                )
                if _logger.isEnabledFor(logging.DEBUG):
                    start_time = time.time()
                method(cr, uid, *args)
                if _logger.isEnabledFor(logging.DEBUG):
                    end_time = time.time()
                    _logger.debug("%.3fs (%s, %s)" % (end_time - start_time, model_name, method_name))
            except Exception, e:
                self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e)
Ejemplo n.º 2
0
    def _callback(self, cr, uid, model_name, method_name, args, job_id):
        """ Run the method associated to a given job

        It takes care of logging and exception handling.

        :param model_name: model name on which the job method is located.
        :param method_name: name of the method to call when this job is processed.
        :param args: arguments of the method (without the usual self, cr, uid).
        :param job_id: job id.
        """
        args = str2tuple(args)
        model = self.pool.get(model_name)
        if model and hasattr(model, method_name):
            method = getattr(model, method_name)
            try:
                log_depth = (None
                             if _logger.isEnabledFor(logging.DEBUG) else 1)
                netsvc.log(_logger,
                           logging.DEBUG,
                           'cron.object.execute',
                           (cr.dbname, uid, '*', model_name, method_name) +
                           tuple(args),
                           depth=log_depth)
                if _logger.isEnabledFor(logging.DEBUG):
                    start_time = time.time()
                method(cr, uid, *args)
                if _logger.isEnabledFor(logging.DEBUG):
                    end_time = time.time()
                    _logger.debug(
                        '%.3fs (%s, %s)' %
                        (end_time - start_time, model_name, method_name))
            except Exception, e:
                self._handle_callback_exception(cr, uid, model_name,
                                                method_name, args, job_id, e)
Ejemplo n.º 3
0
 def _callback(self, cr, uid, model, func, args, job_id):
     args = str2tuple(args)
     m = self.pool.get(model)
     if m and hasattr(m, func):
         f = getattr(m, func)
         try:
             netsvc.log('cron', (cr.dbname,uid,'*',model,func)+tuple(args), channel=logging.DEBUG,
                         depth=(None if self._logger.isEnabledFor(logging.DEBUG_RPC_ANSWER) else 1), fn='object.execute')
             logger = logging.getLogger('execution time')
             if logger.isEnabledFor(logging.DEBUG):
                 start_time = time.time()
             f(cr, uid, *args)
             if logger.isEnabledFor(logging.DEBUG):
                 end_time = time.time()
                 logger.log(logging.DEBUG, '%.3fs (%s, %s)' % (end_time - start_time, model, func))
         except Exception, e:
             self._handle_callback_exception(cr, uid, model, func, args, job_id, e)