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) call_log = '' 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) start_time = time.time() call_resu = method(cr, uid, *args) if call_resu: call_log += "return result:\n" + str(call_resu) + "\n" end_time = time.time() msg = '%.3fs (%s, %s)' % (end_time - start_time, model_name, method_name) call_log += msg + "\n" if _logger.isEnabledFor(logging.DEBUG): _logger.debug(msg) return call_log except Exception, e: self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e) #raise the original exception, 11/15/2015, johnw raise
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)
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. """ try: args = str2tuple(args) openerp.modules.registry.RegistryManager.check_registry_signaling(cr.dbname) registry = openerp.registry(cr.dbname) if model_name in registry: model = registry[model_name] if hasattr(model, method_name): 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() getattr(model, method_name)(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)) openerp.modules.registry.RegistryManager.signal_caches_change(cr.dbname) else: msg = "Method `%s.%s` does not exist." % (model_name, method_name) _logger.warning(msg) else: msg = "Model `%s` does not exist." % model_name _logger.warning(msg) except Exception, e: self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e)
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)
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) call_log = '' 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) #johnw, 12/02/2014, log the message ''' 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)) ''' start_time = time.time() call_resu = method(cr, uid, *args) if call_resu: call_log += "return result:\n%s\n" % (call_resu) end_time = time.time() msg = '%.3fs (%s, %s)' % (end_time - start_time, model_name, method_name) call_log += msg + "\n" if _logger.isEnabledFor(logging.DEBUG): _logger.debug(msg) return call_log except Exception, e: self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e) #raise the original exception, 11/15/2015, johnw raise
def _callback(self, cr, uid, model_name, method_name, args, job_id): ''' Executes the scheduler only if it can be executed according to its punchcard AND the system's parameter do_not_execute_schedulers is not set to True. ''' # If we have a system's parameter which is called 'do_not_execute_schedulers' and it # is set to True, then we do not execute the scheduler. do_not_execute_schedulers = safe_eval( self.pool.get('ir.config_parameter').get_param( cr, uid, 'do_not_execute_schedulers', 'False')) if do_not_execute_schedulers is True: return False # If, according to punchcards, it can not execute the scheduler, returns False. punch_values = self._check_punchcard(cr, uid, job_id) if not punch_values: return False ir_cron_punchcard_obj = self.pool.get('ir.cron.punchcard') # If we can execute, we log the punchcard... ir_cron_punchcard_obj.create(cr, uid, punch_values) # We limit the number of punchcards to the amount indicated in the configuration, thus # we remove the extra ones (keeping only the newest ones). configuration = self.pool.get('configuration.data').get(cr, uid, []) if configuration.punchcards_limit: punchcards_to_keep_ids = ir_cron_punchcard_obj.search( cr, uid, [('ir_cron', '=', job_id)], limit=configuration.punchcards_limit, order='execution_day DESC') if punchcards_to_keep_ids: punchards_to_remove_ids = ir_cron_punchcard_obj.search( cr, uid, [ ('ir_cron', '=', job_id), ('id', 'not in', punchcards_to_keep_ids), ]) ir_cron_punchcard_obj.unlink(cr, uid, punchards_to_remove_ids) # ... and continue with the normal execution of the scheduler. args = str2tuple(args) model = self.pool.get(model_name) ret = False 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() ret = method(cr, uid, *args) if ret and isinstance(ret, str): ctx = {'thread_id': job_id, 'thread_model': 'ir.cron'} if logger.isEnabledFor(logging.DEBUG): end_time = time.time() logger.debug( '%.3fs (%s, %s)' % (end_time - start_time, model_name, method_name)) except Exception as e: self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e) return ret
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. """ cron_log_obj = self.pool.get('ir.cron.log') cron_log_id = cron_log_obj.create(cr, SUPERUSER_ID, {'cron_id': job_id}, context=None) date_start = None try: args = str2tuple(args) openerp.modules.registry.RegistryManager.check_registry_signaling( cr.dbname) registry = openerp.registry(cr.dbname) if model_name in registry: model = registry[model_name] if hasattr(model, method_name): 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) # Set the cron status as in-progress cron_log_obj.write(cr, SUPERUSER_ID, [cron_log_id], {'status': 'in-progress'}, context=None) # Executes the method and tracks the elapsed time start_time = time.time() date_start = openerp.fields.Datetime.now() getattr(model, method_name)(cr, uid, *args) date_end = openerp.fields.Datetime.now() end_time = time.time() # Cron executed succesfully, store the result cron_log_obj.write(cr, SUPERUSER_ID, [cron_log_id], { 'status': 'done', 'date_start': date_start, 'date_end': date_end }, context=None) if _logger.isEnabledFor(logging.DEBUG): _logger.debug( '%.3fs (%s, %s)' % (end_time - start_time, model_name, method_name)) openerp.modules.registry.RegistryManager.signal_caches_change( cr.dbname) else: msg = "Method `%s.%s` does not exist." % (model_name, method_name) _logger.warning(msg) # No method found, save the unused call cron_log_obj.write(cr, SUPERUSER_ID, [cron_log_id], { 'status': 'error', 'error_message': msg }, context=None) else: msg = "Model `%s` does not exist." % model_name _logger.warning(msg) # No model found, save the unused call cron_log_obj.write(cr, SUPERUSER_ID, [cron_log_id], { 'status': 'error', 'error_message': msg }, context=None) except Exception, e: # An exception is raised during execution, save the result date_end = openerp.fields.Datetime.now() cron_log_obj.write(cr, SUPERUSER_ID, [cron_log_id], { 'status': 'error', 'date_start': date_start, 'date_end': date_end, 'error_message': e.message }, context=None) self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e)
def _callback_now(self, cr, uid, model_name, method_name, args, job_id, cron_cr, now): """ 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. """ try: args = str2tuple(args) openerp.modules.registry.RegistryManager.check_registry_signaling( cr.dbname) registry = openerp.registry(cr.dbname) if model_name in registry: model = registry[model_name] if hasattr(model, method_name): 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() getattr(model, method_name)(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)) openerp.modules.registry.RegistryManager.signal_caches_change( cr.dbname) else: # update num_of_failed_runs counter if method is not found try: cron_cr.execute( "UPDATE ir_cron SET num_of_failed_runs = num_of_failed_runs + 1, last_failed_date = %s, last_run_date = %s WHERE id=%s;", ( now, now, job_id, )) except: cron_cr.rollback() print "Error 1" pass msg = "Method `%s.%s` does not exist." % (model_name, method_name) _logger.warning(msg) else: # update num_of_failed_runs counter if method is not found try: cron_cr.execute( "UPDATE ir_cron SET num_of_failed_runs = num_of_failed_runs + 1, last_failed_date = %s, last_run_date = %s WHERE id=%s;", ( now, now, job_id, )) except: cron_cr.rollback() print "Error 2" pass msg = "Model `%s` does not exist." % model_name _logger.warning(msg) except Exception, e: # update num_of_failed_runs counter if method is not found try: cron_cr.execute( "UPDATE ir_cron SET num_of_failed_runs = num_of_failed_runs + 1, last_failed_date = %s, last_run_date = %s WHERE id=%s;", ( now, now, job_id, )) except: cron_cr.rollback() print "Error 3" pass self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e)