kisa-utils 0.42.4__py3-none-any.whl → 0.42.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kisa_utils/db.py +16 -2
- kisa_utils/queues/persistent.py +4 -7
- {kisa_utils-0.42.4.dist-info → kisa_utils-0.42.6.dist-info}/METADATA +1 -1
- {kisa_utils-0.42.4.dist-info → kisa_utils-0.42.6.dist-info}/RECORD +6 -6
- {kisa_utils-0.42.4.dist-info → kisa_utils-0.42.6.dist-info}/WHEEL +0 -0
- {kisa_utils-0.42.4.dist-info → kisa_utils-0.42.6.dist-info}/top_level.txt +0 -0
kisa_utils/db.py
CHANGED
|
@@ -7,6 +7,7 @@ import inspect
|
|
|
7
7
|
import traceback
|
|
8
8
|
import re
|
|
9
9
|
from threading import get_native_id as getCurrentThreadId, Lock
|
|
10
|
+
import random, time
|
|
10
11
|
|
|
11
12
|
from . import storage
|
|
12
13
|
from . import codes
|
|
@@ -142,6 +143,7 @@ class Api:
|
|
|
142
143
|
accessFromMultipleThreads:bool = False,
|
|
143
144
|
useWALMode:bool = True,
|
|
144
145
|
returnKISAResponse:bool|None = None,
|
|
146
|
+
connectionTimeout:float = 30.0
|
|
145
147
|
):
|
|
146
148
|
'''
|
|
147
149
|
attempt to open an sqlite3 database connection object/instance
|
|
@@ -238,9 +240,21 @@ class Api:
|
|
|
238
240
|
|
|
239
241
|
self._readonly = True if readonly else False
|
|
240
242
|
|
|
241
|
-
self.db:sqlite3.Connection
|
|
243
|
+
self.db:sqlite3.Connection
|
|
244
|
+
|
|
245
|
+
max_retries = 4
|
|
246
|
+
for attempt in range(max_retries):
|
|
247
|
+
try:
|
|
248
|
+
self.db = sqlite3.connect(path, check_same_thread = not accessFromMultipleThreads, timeout=connectionTimeout)
|
|
249
|
+
break
|
|
250
|
+
except sqlite3.OperationalError as e:
|
|
251
|
+
if attempt == max_retries - 1:
|
|
252
|
+
raise # Re-raise on final attempt
|
|
253
|
+
|
|
254
|
+
wait_time = (2 ** attempt) + random.uniform(0, 1) # Exponential backoff with jitter
|
|
255
|
+
print(f"Database connection attempt {attempt + 1} failed: {e}. Retrying in {wait_time:.2f}s...")
|
|
256
|
+
time.sleep(wait_time)
|
|
242
257
|
|
|
243
|
-
self.db = sqlite3.connect(path, check_same_thread = not accessFromMultipleThreads)
|
|
244
258
|
if useWALMode:
|
|
245
259
|
self.db.executescript(f'''
|
|
246
260
|
/* set journal mode to WAL and `synchronous` to best value, which works best for WAL mode*/
|
kisa_utils/queues/persistent.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
from kisa_utils.db import Handle
|
|
2
|
-
from kisa_utils import db
|
|
3
2
|
from kisa_utils.queues.callables import queueCallsInThreads
|
|
4
3
|
from kisa_utils.response import Response, Error, Ok
|
|
5
4
|
from kisa_utils.dataStructures import KDict
|
|
@@ -8,8 +7,6 @@ from kisa_utils import dates
|
|
|
8
7
|
from kisa_utils.functionUtils import enforceRequirements
|
|
9
8
|
from kisa_utils.structures.utils import Value
|
|
10
9
|
|
|
11
|
-
db.RETURN_KISA_RESPONSES = True
|
|
12
|
-
|
|
13
10
|
class __PersistentQueueSingleton(type):
|
|
14
11
|
_instances = {}
|
|
15
12
|
|
|
@@ -115,7 +112,7 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
115
112
|
load underlying queue database
|
|
116
113
|
'''
|
|
117
114
|
|
|
118
|
-
with Handle(self.dbPath, tables=self.__schema) as handle:
|
|
115
|
+
with Handle(self.dbPath, tables=self.__schema, returnKISAResponse=True) as handle:
|
|
119
116
|
if not (resp := handle.fetch('data', ['count(*)'],'',[])):
|
|
120
117
|
return resp
|
|
121
118
|
|
|
@@ -149,7 +146,7 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
149
146
|
return Error(f'failed to get data-type of `{data}`')
|
|
150
147
|
|
|
151
148
|
|
|
152
|
-
with Handle(self.dbPath, readonly=False) as handle:
|
|
149
|
+
with Handle(self.dbPath, readonly=False, returnKISAResponse=True) as handle:
|
|
153
150
|
if not (resp := handle.insert('data', [
|
|
154
151
|
dates.currentTimestamp(),
|
|
155
152
|
dataType,
|
|
@@ -167,7 +164,7 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
167
164
|
if not (resp := self.__resolveIndex(index)): return resp
|
|
168
165
|
index = resp.data
|
|
169
166
|
|
|
170
|
-
with Handle(self.dbPath) as handle:
|
|
167
|
+
with Handle(self.dbPath, returnKISAResponse=True) as handle:
|
|
171
168
|
if not (resp := handle.fetch('data', ['dataType', 'data'],'',[],limit=1, offset=index, parseJson=True)):
|
|
172
169
|
return resp
|
|
173
170
|
|
|
@@ -187,7 +184,7 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
187
184
|
if not (resp := self.__resolveIndex(index)): return resp
|
|
188
185
|
index = resp.data
|
|
189
186
|
|
|
190
|
-
with Handle(self.dbPath, readonly=False) as handle:
|
|
187
|
+
with Handle(self.dbPath, readonly=False, returnKISAResponse=True) as handle:
|
|
191
188
|
if not (resp := handle.fetch('data', ['rowid','dataType', 'data'],'',[],limit=1, offset=index, parseJson=True)):
|
|
192
189
|
return resp
|
|
193
190
|
|
|
@@ -4,7 +4,7 @@ kisa_utils/codes.py,sha256=PV_S53Skggf4XetOdYoIKtEmM8cpN5wZwUlxje70WZY,904
|
|
|
4
4
|
kisa_utils/config.py,sha256=NfluzGKTh66qfNtC-Ae0zNb1XzMTgU2Me9Vi82R9c1E,2285
|
|
5
5
|
kisa_utils/dataStructures.py,sha256=ZgLpttJ66jfpU1NWzLDD1Czqxzj6sWereffgTQWhlV8,2679
|
|
6
6
|
kisa_utils/dates.py,sha256=zxe4n0PdKReZjK5ZkvnCZtJ55lk5oqu9oS8VX_nLozw,13966
|
|
7
|
-
kisa_utils/db.py,sha256
|
|
7
|
+
kisa_utils/db.py,sha256=-0Q7iw9VEtf4oyOIj_IhJqmzeh0CZVp3vEcwIQn4Zls,54939
|
|
8
8
|
kisa_utils/encryption.py,sha256=nFzNpzWV_D9uSEq4FsgCnlS7FQtqWP9fvM_81rsfcLo,4218
|
|
9
9
|
kisa_utils/figures.py,sha256=pYIpQzu1OXRSsY1d98GhgPifnIRmgl-r7S32ai-Ms0c,3731
|
|
10
10
|
kisa_utils/functionUtils.py,sha256=PlXjnmU1uJWNdISlJJ3SCgavTsgNBoebaa9dtWSFhRA,6553
|
|
@@ -18,7 +18,7 @@ kisa_utils/token.py,sha256=Y2qglWYWpmHxoXBh-TH0r1as0uPV5LLqMNcunLvM4vM,7850
|
|
|
18
18
|
kisa_utils/permissions/__config__.py,sha256=i3ELkOydDnjKx2ozQTxLZdZ8DXSeUncnl2kRxANjFmM,613
|
|
19
19
|
kisa_utils/permissions/__init__.py,sha256=iAsGEf5Ktw3gPJ5ZKL8BnuqX8e_S4QgsCVgfaRYi4Qg,48068
|
|
20
20
|
kisa_utils/queues/__init__.py,sha256=VvhceyN5qeiMel1JFQwLRuVk48oBXaWvDtriCubDOms,48
|
|
21
|
-
kisa_utils/queues/persistent.py,sha256=
|
|
21
|
+
kisa_utils/queues/persistent.py,sha256=Gie6eUX44BLzC2udO4mbP-njA6BRbsovlMcDNQKFXJM,6706
|
|
22
22
|
kisa_utils/queues/callables/__init__.py,sha256=OJL3AQnaAS1Eek4H6WBH3WefA2wf-x03cwFmRSK8hoU,141
|
|
23
23
|
kisa_utils/queues/callables/enqueueFunctionCalls.py,sha256=VIliaMvw4MUdOqts0dXdZCYNxs-QrOVjIRAR3scGrRM,11786
|
|
24
24
|
kisa_utils/queues/callables/executorQueues.py,sha256=x6bAqxBSZRZ_kL8CK1lSN6JYAYFLxzM84LC1RmwaOLw,6626
|
|
@@ -27,7 +27,7 @@ kisa_utils/servers/flask.py,sha256=XZYY1pWnP1mSvaS5Uv8G3EFJV5BJBQtU2gDbO8suvLc,4
|
|
|
27
27
|
kisa_utils/structures/__init__.py,sha256=JBU1j3A42jQ62ALKnsS1Hav9YXcYwjDw1wQJtohXPbU,83
|
|
28
28
|
kisa_utils/structures/utils.py,sha256=665rXIapGwFqejizeJwy3DryeskCQOdgP25BCdLkGvk,2898
|
|
29
29
|
kisa_utils/structures/validator.py,sha256=JhD9jcfbjTwBr_7OfuNaJd_cYr7wR2emFhsCEo5MCHQ,4323
|
|
30
|
-
kisa_utils-0.42.
|
|
31
|
-
kisa_utils-0.42.
|
|
32
|
-
kisa_utils-0.42.
|
|
33
|
-
kisa_utils-0.42.
|
|
30
|
+
kisa_utils-0.42.6.dist-info/METADATA,sha256=Dyk0-x1A4skPorhBkLVW6Dwf2Qs7WgilsaMlLR3mXTE,477
|
|
31
|
+
kisa_utils-0.42.6.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
32
|
+
kisa_utils-0.42.6.dist-info/top_level.txt,sha256=GFOLXZYqpBG9xtscGa2uGJAEiZ5NwsqHBH9NylnB29M,11
|
|
33
|
+
kisa_utils-0.42.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|