summaryrefslogtreecommitdiff
path: root/searx/search/processors/offline.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-04-13 15:21:53 +0200
committerAlexandre Flament <alex@al-f.net>2021-04-21 16:24:46 +0200
commitaae7830d14242ac1f98232f428654c5d2c9c5eb2 (patch)
tree83df1950b7b5889fb17eda740a095022a816642e /searx/search/processors/offline.py
parentae5954f2dad0386868709a59a1b29d005ebb2b2d (diff)
[mod] refactoring: processors
Report to the user suspended engines. searx.search.processor.abstract: * manages suspend time (per network). * reports suspended time to the ResultContainer (method extend_container_if_suspended) * adds the results to the ResultContainer (method extend_container) * handles exceptions (method handle_exception)
Diffstat (limited to 'searx/search/processors/offline.py')
-rw-r--r--searx/search/processors/offline.py33
1 files changed, 4 insertions, 29 deletions
diff --git a/searx/search/processors/offline.py b/searx/search/processors/offline.py
index ede8eb5e1..5186b346a 100644
--- a/searx/search/processors/offline.py
+++ b/searx/search/processors/offline.py
@@ -1,51 +1,26 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
-import threading
-from time import time
from searx import logger
-from searx.metrology.error_recorder import record_exception, record_error
from searx.search.processors.abstract import EngineProcessor
-logger = logger.getChild('search.processor.offline')
+logger = logger.getChild('searx.search.processor.offline')
class OfflineProcessor(EngineProcessor):
engine_type = 'offline'
- def _record_stats_on_error(self, result_container, start_time):
- engine_time = time() - start_time
- result_container.add_timing(self.engine_name, engine_time, engine_time)
-
- with threading.RLock():
- self.engine.stats['errors'] += 1
-
def _search_basic(self, query, params):
return self.engine.search(query, params)
def search(self, query, params, result_container, start_time, timeout_limit):
try:
search_results = self._search_basic(query, params)
-
- if search_results:
- result_container.extend(self.engine_name, search_results)
-
- engine_time = time() - start_time
- result_container.add_timing(self.engine_name, engine_time, engine_time)
- with threading.RLock():
- self.engine.stats['engine_time'] += engine_time
- self.engine.stats['engine_time_count'] += 1
-
+ self.extend_container(result_container, start_time, search_results)
except ValueError as e:
- record_exception(self.engine_name, e)
- self._record_stats_on_error(result_container, start_time)
+ # do not record the error
logger.exception('engine {0} : invalid input : {1}'.format(self.engine_name, e))
except Exception as e:
- record_exception(self.engine_name, e)
- self._record_stats_on_error(result_container, start_time)
- result_container.add_unresponsive_engine(self.engine_name, 'unexpected crash', str(e))
+ self.handle_exception(result_container, 'unexpected crash', e)
logger.exception('engine {0} : exception : {1}'.format(self.engine_name, e))
- else:
- if getattr(threading.current_thread(), '_timeout', False):
- record_error(self.engine_name, 'Timeout')