1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-19 02:40:11 +01:00

[fix] offline engine: don't crash on time recording

This commit is contained in:
Alexandre Flament 2021-05-19 11:24:18 +02:00 committed by Markus Heiser
parent 2f76b570ab
commit ec83493538
3 changed files with 15 additions and 12 deletions

View File

@ -44,7 +44,8 @@ def reset_time_for_thread():
def get_time_for_thread(): def get_time_for_thread():
return THREADLOCAL.total_time """returns thread's total time or None"""
return THREADLOCAL.__dict__.get('total_time')
def set_timeout_for_thread(timeout, start_time=None): def set_timeout_for_thread(timeout, start_time=None):
@ -57,10 +58,11 @@ def set_context_network_name(network_name):
def get_context_network(): def get_context_network():
try: """If set return thread's network.
return THREADLOCAL.network
except AttributeError: If unset, return value from :py:obj:`get_network`.
return get_network() """
return THREADLOCAL.__dict__.get('network') or get_network()
def request(method, url, **kwargs): def request(method, url, **kwargs):

View File

@ -371,11 +371,12 @@ class ResultContainer:
self.unresponsive_engines.add((engine_name, error_type, error_message, suspended)) self.unresponsive_engines.add((engine_name, error_type, error_message, suspended))
def add_timing(self, engine_name, engine_time, page_load_time): def add_timing(self, engine_name, engine_time, page_load_time):
self.timings.append({ timing = {
'engine': engines[engine_name].shortcut, 'engine': engines[engine_name].shortcut,
'total': engine_time, 'total': engine_time,
'load': page_load_time 'load': page_load_time,
}) }
self.timings.append(timing)
def get_timings(self): def get_timings(self):
return self.timings return self.timings

View File

@ -568,7 +568,7 @@ def post_request(response):
timings_total = ['total_' + str(i) + '_' + v['engine'] + timings_total = ['total_' + str(i) + '_' + v['engine'] +
';dur=' + str(round(v['total'] * 1000, 3)) for i, v in enumerate(timings)] ';dur=' + str(round(v['total'] * 1000, 3)) for i, v in enumerate(timings)]
timings_load = ['load_' + str(i) + '_' + v['engine'] + timings_load = ['load_' + str(i) + '_' + v['engine'] +
';dur=' + str(round(v['load'] * 1000, 3)) for i, v in enumerate(timings)] ';dur=' + str(round(v['load'] * 1000, 3)) for i, v in enumerate(timings) if v.get('load')]
timings_all = timings_all + timings_total + timings_load timings_all = timings_all + timings_total + timings_load
response.headers.add('Server-Timing', ', '.join(timings_all)) response.headers.add('Server-Timing', ', '.join(timings_all))
return response return response
@ -923,9 +923,9 @@ def preferences():
result_count = int(result_count_sum / float(successful_count)) if successful_count else 0 result_count = int(result_count_sum / float(successful_count)) if successful_count else 0
stats[e.name] = { stats[e.name] = {
'time': median if median else None, 'time': median,
'rate80': rate80 if rate80 else None, 'rate80': rate80,
'rate95': rate95 if rate95 else None, 'rate95': rate95,
'warn_timeout': e.timeout > settings['outgoing']['request_timeout'], 'warn_timeout': e.timeout > settings['outgoing']['request_timeout'],
'supports_selected_language': _is_selected_language_supported(e, request.preferences), 'supports_selected_language': _is_selected_language_supported(e, request.preferences),
'result_count': result_count, 'result_count': result_count,