##// END OF EJS Templates
cache exc store, and use glob.glob for scaning exc store
marcink -
r3975:6411e6b8 default
parent child Browse files
Show More
@@ -25,6 +25,7 b' import msgpack'
25 import logging
25 import logging
26 import traceback
26 import traceback
27 import tempfile
27 import tempfile
28 import glob
28
29
29
30
30 log = logging.getLogger(__name__)
31 log = logging.getLogger(__name__)
@@ -50,13 +51,20 b' def exc_serialize(exc_id, tb, exc_type):'
50 def exc_unserialize(tb):
51 def exc_unserialize(tb):
51 return msgpack.unpackb(tb)
52 return msgpack.unpackb(tb)
52
53
54 _exc_store = None
55
53
56
54 def get_exc_store():
57 def get_exc_store():
55 """
58 """
56 Get and create exception store if it's not existing
59 Get and create exception store if it's not existing
57 """
60 """
61 global _exc_store
58 import rhodecode as app
62 import rhodecode as app
59
63
64 if _exc_store is not None:
65 # quick global cache
66 return _exc_store
67
60 exc_store_dir = app.CONFIG.get('exception_tracker.store_path', '') or tempfile.gettempdir()
68 exc_store_dir = app.CONFIG.get('exception_tracker.store_path', '') or tempfile.gettempdir()
61 _exc_store_path = os.path.join(exc_store_dir, exc_store_dir_name)
69 _exc_store_path = os.path.join(exc_store_dir, exc_store_dir_name)
62
70
@@ -64,6 +72,8 b' def get_exc_store():'
64 if not os.path.isdir(_exc_store_path):
72 if not os.path.isdir(_exc_store_path):
65 os.makedirs(_exc_store_path)
73 os.makedirs(_exc_store_path)
66 log.debug('Initializing exceptions store at %s', _exc_store_path)
74 log.debug('Initializing exceptions store at %s', _exc_store_path)
75 _exc_store = _exc_store_path
76
67 return _exc_store_path
77 return _exc_store_path
68
78
69
79
@@ -119,16 +129,12 b' def _find_exc_file(exc_id, prefix=global'
119 # search without a prefix
129 # search without a prefix
120 exc_id = '{}'.format(exc_id)
130 exc_id = '{}'.format(exc_id)
121
131
122 # we need to search the store for such start pattern as above
132 found_exc_id = None
123 for fname in os.listdir(exc_store_path):
133 matches = glob.glob(os.path.join(exc_store_path, exc_id) + '*')
124 if fname.startswith(exc_id):
134 if matches:
125 exc_id = os.path.join(exc_store_path, fname)
135 found_exc_id = matches[0]
126 break
127 continue
128 else:
129 exc_id = None
130
136
131 return exc_id
137 return found_exc_id
132
138
133
139
134 def _read_exception(exc_id, prefix):
140 def _read_exception(exc_id, prefix):
General Comments 0
You need to be logged in to leave comments. Login now