mirror of https://github.com/searx/searx
[mod] searx.shared: minor tweaks
searx.shared.shared_abstract.SharedDict inherit from abc.ABC searx.shared.shared_uwsgi.schedule can schedule multiple functions without issue
This commit is contained in:
parent
87bafbc32b
commit
a0c8b413a6
|
@ -1,15 +1,21 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
class SharedDict:
|
|
||||||
|
|
||||||
|
class SharedDict(ABC):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def get_int(self, key):
|
def get_int(self, key):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def set_int(self, key, value):
|
def set_int(self, key, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def get_str(self, key):
|
def get_str(self, key):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def set_str(self, key, value):
|
def set_str(self, key, value):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -44,14 +44,15 @@ def schedule(delay, func, *args):
|
||||||
|
|
||||||
def sighandler(signum):
|
def sighandler(signum):
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
|
key = 'scheduler_call_time_signal_' + str(signum)
|
||||||
uwsgi.lock()
|
uwsgi.lock()
|
||||||
try:
|
try:
|
||||||
updating = uwsgi.cache_get('updating')
|
updating = uwsgi.cache_get(key)
|
||||||
if updating is not None:
|
if updating is not None:
|
||||||
updating = int.from_bytes(updating, 'big')
|
updating = int.from_bytes(updating, 'big')
|
||||||
if now - updating < delay:
|
if now - updating < delay:
|
||||||
return
|
return
|
||||||
uwsgi.cache_update('updating', now.to_bytes(4, 'big'))
|
uwsgi.cache_update(key, now.to_bytes(4, 'big'))
|
||||||
finally:
|
finally:
|
||||||
uwsgi.unlock()
|
uwsgi.unlock()
|
||||||
func(*args)
|
func(*args)
|
||||||
|
|
Loading…
Reference in New Issue