diff --git a/bin/addons/base/ir/ir_cron.py b/bin/addons/base/ir/ir_cron.py index e7b1a541f0c..4236caf8d7a 100644 --- a/bin/addons/base/ir/ir_cron.py +++ b/bin/addons/base/ir/ir_cron.py @@ -41,6 +41,9 @@ _intervalTypes = { } class ir_cron(osv.osv, netsvc.Agent): + """ This is the ORM object that periodically executes actions. + Note that we use the netsvc.Agent()._logger member. + """ _name = "ir.cron" _order = 'name' _columns = { @@ -74,7 +77,7 @@ class ir_cron(osv.osv, netsvc.Agent): try: for this in self.browse(cr, uid, ids, context): str2tuple(this.args) - except: + except Exception: return False return True @@ -90,8 +93,7 @@ class ir_cron(osv.osv, netsvc.Agent): try: f(cr, uid, *args) except Exception, e: - self._logger.notifyChannel('timers', netsvc.LOG_ERROR, "Job call of self.pool.get('%s').%s(cr, uid, *%r) failed" % (model, func, args)) - self._logger.notifyChannel('timers', netsvc.LOG_ERROR, tools.exception_to_unicode(e)) + self._logger.exception("Job call of self.pool.get('%s').%s(cr, uid, *%r) failed" % (model, func, args)) def _poolJobs(self, db_name, check=False): @@ -135,9 +137,7 @@ class ir_cron(osv.osv, netsvc.Agent): self.setAlarm(self._poolJobs, next_call, db_name, db_name) except Exception, ex: - logger = netsvc.Logger() - logger.notifyChannel('cron', netsvc.LOG_WARNING, - 'Exception in cron:'+str(ex)) + self._logger.warning('Exception in cron:', exc_info=True) finally: cr.commit() diff --git a/bin/netsvc.py b/bin/netsvc.py index 62b427d5eb1..c2360ae5ee7 100644 --- a/bin/netsvc.py +++ b/bin/netsvc.py @@ -309,7 +309,7 @@ class Agent(object): """ __tasks = [] __tasks_by_db = {} - _logger = Logger() + _logger = logging.getLogger('netsvc.agent') @classmethod def setAlarm(cls, function, timestamp, db_name, *args, **kwargs): @@ -320,6 +320,7 @@ class Agent(object): @classmethod def cancel(cls, db_name): """Cancel all tasks for a given database. If None is passed, all tasks are cancelled""" + cls._logger.debug("Cancel timers for %s db", db_name or 'all') if db_name is None: cls.__tasks, cls.__tasks_by_db = [], {} else: @@ -334,7 +335,7 @@ class Agent(object): @classmethod def runner(cls): """Neverending function (intended to be ran in a dedicated thread) that - checks every 60 seconds tasks to run. + checks every 60 seconds tasks to run. TODO: make configurable """ current_thread = threading.currentThread() while True: @@ -346,7 +347,7 @@ class Agent(object): # null timestamp -> cancelled task continue current_thread.dbname = dbname # hack hack - cls._logger.notifyChannel('timers', LOG_DEBUG, "Run %s.%s(*%r, **%r)" % (function.im_class.__name__, function.func_name, args, kwargs)) + cls._logger.debug("Run %s.%s(*%s, **%s)", function.im_class.__name__, function.func_name, args, kwargs) delattr(current_thread, 'dbname') task_thread = threading.Thread(target=function, name='netsvc.Agent.task', args=args, kwargs=kwargs) # force non-daemon task threads (the runner thread must be daemon, and this property is inherited by default) @@ -362,7 +363,6 @@ agent_runner = threading.Thread(target=Agent.runner, name="netsvc.Agent.runner") agent_runner.setDaemon(True) agent_runner.start() - import traceback class Server: