mirror of
https://github.com/searxng/searxng.git
synced 2025-08-19 02:06:50 +02:00
[enh] add searx.shared
shared dictionary between the workers (UWSGI or werkzeug) scheduler: run a task once every x seconds (UWSGI or werkzeug)
This commit is contained in:
parent
9c581466e1
commit
6e2872f436
7 changed files with 156 additions and 1 deletions
31
searx/shared/__init__.py
Normal file
31
searx/shared/__init__.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger('searx.shared')
|
||||
|
||||
try:
|
||||
import uwsgi
|
||||
except:
|
||||
# no uwsgi
|
||||
from .shared_simple import SimpleSharedDict as SharedDict, schedule
|
||||
logger.info('Use shared_simple implementation')
|
||||
else:
|
||||
try:
|
||||
uwsgi.cache_update('dummy', b'dummy')
|
||||
if uwsgi.cache_get('dummy') != b'dummy':
|
||||
raise Exception()
|
||||
except:
|
||||
# uwsgi.ini configuration problem: disable all scheduling
|
||||
logger.error('uwsgi.ini configuration error, add this line to your uwsgi.ini\n'
|
||||
'cache2 = name=searxcache,items=2000,blocks=2000,blocksize=4096,bitmap=1')
|
||||
from .shared_simple import SimpleSharedDict as SharedDict
|
||||
|
||||
def schedule(delay, func, *args):
|
||||
pass
|
||||
else:
|
||||
# uwsgi
|
||||
from .shared_uwsgi import UwsgiCacheSharedDict as SharedDict, schedule
|
||||
logger.info('Use shared_uwsgi implementation')
|
||||
|
||||
storage = SharedDict()
|
Loading…
Add table
Add a link
Reference in a new issue