@@ -0,0 +1,62 @@
1+# SPDX-License-Identifier: AGPL-3.0-or-later
4+import uwsgi # pylint: disable=E0401
5+from . import shared_abstract
11+class UwsgiCacheSharedDict(shared_abstract.SharedDict):
13+ def get_int(self, key):
14+ value = uwsgi.cache_get(key)
18+ return int.from_bytes(value, 'big')
20+ def set_int(self, key, value):
21+ b = value.to_bytes(4, 'big')
22+ uwsgi.cache_update(key, b)
24+ def get_str(self, key):
25+ value = uwsgi.cache_get(key)
29+ return value.decode('utf-8')
31+ def set_str(self, key, value):
32+ b = value.encode('utf-8')
33+ uwsgi.cache_update(key, b)
36+def schedule(delay, func, *args):
38+ Can be implemented using a spooler.
39+ https://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html
41+ To make the uwsgi configuration simple, use the alternative implementation.
45+ def sighandler(signum):
46+ now = int(time.time())
49+ updating = uwsgi.cache_get('updating')
50+ if updating is not None:
51+ updating = int.from_bytes(updating, 'big')
52+ if now - updating < delay:
54+ uwsgi.cache_update('updating', now.to_bytes(4, 'big'))
59+ signal_num = _last_signal
61+ uwsgi.register_signal(signal_num, 'worker', sighandler)
62+ uwsgi.add_timer(signal_num, delay)