diff options
| author | Alexandre Flament <alex@al-f.net> | 2022-07-15 18:38:32 +0200 |
|---|---|---|
| committer | Alexandre Flament <alex@al-f.net> | 2022-11-05 12:04:50 +0100 |
| commit | fe419e355bf1527c51e3aee98495d08b89510320 (patch) | |
| tree | 0ed03d5e3d77e68ac5a5834e5890f5f27fe29fe7 /searx/shared/shared_uwsgi.py | |
| parent | d764d94a70b0b10291105a867227975d59af5675 (diff) | |
The checker requires Redis
Remove the abstraction in searx.shared.SharedDict.
Implement a basic and dedicated scheduler for the checker using a Redis script.
Diffstat (limited to 'searx/shared/shared_uwsgi.py')
| -rw-r--r-- | searx/shared/shared_uwsgi.py | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/searx/shared/shared_uwsgi.py b/searx/shared/shared_uwsgi.py deleted file mode 100644 index 0248c6234..000000000 --- a/searx/shared/shared_uwsgi.py +++ /dev/null @@ -1,64 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later - -import time -from typing import Optional -import uwsgi # pyright: ignore # pylint: disable=E0401 -from . import shared_abstract - - -_last_signal = 10 - - -class UwsgiCacheSharedDict(shared_abstract.SharedDict): - def get_int(self, key: str) -> Optional[int]: - value = uwsgi.cache_get(key) - if value is None: - return value - else: - return int.from_bytes(value, 'big') - - def set_int(self, key: str, value: int): - b = value.to_bytes(4, 'big') - uwsgi.cache_update(key, b) - - def get_str(self, key: str) -> Optional[str]: - value = uwsgi.cache_get(key) - if value is None: - return value - else: - return value.decode('utf-8') - - def set_str(self, key: str, value: str): - b = value.encode('utf-8') - uwsgi.cache_update(key, b) - - -def schedule(delay, func, *args): - """ - Can be implemented using a spooler. - https://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html - - To make the uwsgi configuration simple, use the alternative implementation. - """ - global _last_signal - - def sighandler(signum): - now = int(time.time()) - key = 'scheduler_call_time_signal_' + str(signum) - uwsgi.lock() - try: - updating = uwsgi.cache_get(key) - if updating is not None: - updating = int.from_bytes(updating, 'big') - if now - updating < delay: - return - uwsgi.cache_update(key, now.to_bytes(4, 'big')) - finally: - uwsgi.unlock() - func(*args) - - signal_num = _last_signal - _last_signal += 1 - uwsgi.register_signal(signal_num, 'worker', sighandler) - uwsgi.add_timer(signal_num, delay) - return True |