def push_all_dumps(): from . import getapi api = getapi() dump_lib.settings = settings with dump_lib.dumps_lock: for dump_id in dump_lib.list_all_dumps_ids(): dump = dump_lib.load_dump(dump_id, True) api.errordump_store(Config.TOMATO_MODULE_WEB, dump, store_key=settings.get_dumpmanager_api_key()) dump_lib.remove_dump(dump_id)
def dumpException(dump_on_error=True): errorgroup_id = None try: if settings.get_dump_config()[Config.DUMPS_ENABLED]: (type_, exc, _) = sys.exc_info() # web-specific error checks and wrapping from . import AuthError if type_ == AuthError: return if type_ == xmlrpclib.ProtocolError: if exc.errcode == 401: return # prepare backend dumplib for web context dump_lib.tomato_component = Config.TOMATO_MODULE_WEB dump_lib.tomato_version = getVersionStr() dump_lib.settings = settings # dump dump_id = dump_lib.dumpException() if dump_id is None: # try to reconstruct exception group id if isinstance(exc, Error): errorgroup_id = "Error__"+exc.group_id() #fixme: add a second boolean field that indicates whether an error has been dumped else: errorgroup_id = dump_lib.load_dump(dump_id, False)["group_id"] push_all_dumps() except: # avoid endless recursion if dump_on_error: dumpException(dump_on_error=False) return errorgroup_id
def dump_pusher(): # there must be one thread running this. # this thread is started in init() while auto_push: time.sleep(5) # avoid flooding: only one dump per 5 seconds via push! try: with dump_lib.dumps_lock: if len(dump_lib.dumps) > 0: # get dump_id with smallest timestamp dump_id = sorted(dump_lib.dumps.iteritems(), key=lambda d: d[1]['timestamp'])[0][0] # push to backend_debug get_backend_debug_proxy().dump_push_from_backend( settings.get_tomato_module_name(), dump_lib.load_dump(dump_id, load_data=True)) # remove from list dump_lib.remove_dump(dump_id) else: must_autopush.clear() except: must_autopush.clear() # wait for next round if an error occurred. must_autopush.wait()