"""
__tasks = []
__tasks_by_db = {}
- _logger = Logger()
+ _logger = logging.getLogger('netsvc.agent')
@classmethod
def setAlarm(cls, function, timestamp, db_name, *args, **kwargs):
@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:
@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:
# 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)
agent_runner.setDaemon(True)
agent_runner.start()
-
import traceback
class Server:
return args
class OpenERPDispatcher:
- def log(self, title, msg, channel=logging.DEBUG_RPC, depth=2):
+ def log(self, title, msg, channel=logging.DEBUG_RPC, depth=None):
logger = logging.getLogger(title)
if logger.isEnabledFor(channel):
- for line in pformat(msg, depth=100).split('\n'):
+ for line in pformat(msg, depth=depth).split('\n'):
logger.log(channel, line)
def dispatch(self, service_name, method, params):
logger = logging.getLogger('result')
self.log('service', service_name)
self.log('method', method)
- self.log('params', replace_request_password(params), depth=(logger.isEnabledFor(logging.DEBUG_RPC_ANSWER) and 3 or 1))
+ self.log('params', replace_request_password(params), depth=(None if logger.isEnabledFor(logging.DEBUG_RPC_ANSWER) else 1))
auth = getattr(self, 'auth_provider', None)
result = ExportService.getService(service_name).dispatch(method, auth, params)
- self.log('result', result, channel=logging.DEBUG_RPC_ANSWER, depth=(logger.isEnabledFor(logging.DEBUG_SQL) and 5 or 3))
+ self.log('result', result, channel=logging.DEBUG_RPC_ANSWER)
return result
except Exception, e:
self.log('exception', tools.exception_to_unicode(e))