nucliadb-utils 2.46.1.post388__py3-none-any.whl → 2.46.1.post390__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.
- nucliadb_utils/settings.py +3 -0
- nucliadb_utils/tests/unit/test_transaction.py +19 -2
- nucliadb_utils/transaction.py +10 -1
- nucliadb_utils/utilities.py +1 -0
- {nucliadb_utils-2.46.1.post388.dist-info → nucliadb_utils-2.46.1.post390.dist-info}/METADATA +3 -3
- {nucliadb_utils-2.46.1.post388.dist-info → nucliadb_utils-2.46.1.post390.dist-info}/RECORD +9 -9
- {nucliadb_utils-2.46.1.post388.dist-info → nucliadb_utils-2.46.1.post390.dist-info}/WHEEL +0 -0
- {nucliadb_utils-2.46.1.post388.dist-info → nucliadb_utils-2.46.1.post390.dist-info}/top_level.txt +0 -0
- {nucliadb_utils-2.46.1.post388.dist-info → nucliadb_utils-2.46.1.post390.dist-info}/zip-safe +0 -0
nucliadb_utils/settings.py
CHANGED
@@ -166,6 +166,9 @@ class TransactionSettings(BaseSettings):
|
|
166
166
|
transaction_jetstream_auth: Optional[str] = None
|
167
167
|
transaction_jetstream_servers: List[str] = ["nats://localhost:4222"]
|
168
168
|
transaction_local: bool = False
|
169
|
+
transaction_commit_timeout: int = Field(
|
170
|
+
default=60, description="Transaction commit timeout in seconds"
|
171
|
+
)
|
169
172
|
|
170
173
|
|
171
174
|
transaction_settings = TransactionSettings()
|
@@ -17,12 +17,17 @@
|
|
17
17
|
# You should have received a copy of the GNU Affero General Public License
|
18
18
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
+
import asyncio
|
20
21
|
from unittest import mock
|
21
22
|
|
22
23
|
import pytest
|
23
|
-
from nucliadb_protos.writer_pb2 import Notification
|
24
|
+
from nucliadb_protos.writer_pb2 import BrokerMessage, Notification
|
24
25
|
|
25
|
-
from nucliadb_utils.transaction import
|
26
|
+
from nucliadb_utils.transaction import (
|
27
|
+
TransactionCommitTimeoutError,
|
28
|
+
TransactionUtility,
|
29
|
+
WaitFor,
|
30
|
+
)
|
26
31
|
|
27
32
|
|
28
33
|
@pytest.fixture()
|
@@ -100,3 +105,15 @@ async def test_wait_for_commit_stop_waiting(txn: TransactionUtility, pubsub):
|
|
100
105
|
# Unsubscribing twice with the same request_id should raise KeyError
|
101
106
|
with pytest.raises(KeyError):
|
102
107
|
await txn.stop_waiting(kbid, request_id=request_id)
|
108
|
+
|
109
|
+
|
110
|
+
@pytest.mark.asyncio
|
111
|
+
async def test_commit_timeout(txn: TransactionUtility, pubsub):
|
112
|
+
txn.js = mock.AsyncMock()
|
113
|
+
bm = BrokerMessage()
|
114
|
+
|
115
|
+
waiting_event = mock.Mock(wait=mock.Mock(side_effect=asyncio.TimeoutError))
|
116
|
+
txn.wait_for_commited = mock.AsyncMock(return_value=waiting_event) # type: ignore
|
117
|
+
|
118
|
+
with pytest.raises(TransactionCommitTimeoutError):
|
119
|
+
await txn.commit(bm, 1, wait=True, target_subject="foo")
|
nucliadb_utils/transaction.py
CHANGED
@@ -49,6 +49,10 @@ class WaitFor:
|
|
49
49
|
self.seq = seq
|
50
50
|
|
51
51
|
|
52
|
+
class TransactionCommitTimeoutError(Exception):
|
53
|
+
pass
|
54
|
+
|
55
|
+
|
52
56
|
class LocalTransactionUtility:
|
53
57
|
async def commit(
|
54
58
|
self,
|
@@ -85,9 +89,11 @@ class TransactionUtility:
|
|
85
89
|
self,
|
86
90
|
nats_servers: list[str],
|
87
91
|
nats_creds: Optional[str] = None,
|
92
|
+
commit_timeout: int = 60,
|
88
93
|
):
|
89
94
|
self.nats_creds = nats_creds
|
90
95
|
self.nats_servers = nats_servers
|
96
|
+
self.commit_timeout = commit_timeout
|
91
97
|
|
92
98
|
async def disconnected_cb(self):
|
93
99
|
logger.info("Got disconnected from NATS!")
|
@@ -201,9 +207,12 @@ class TransactionUtility:
|
|
201
207
|
|
202
208
|
if wait and waiting_event is not None:
|
203
209
|
try:
|
204
|
-
await asyncio.wait_for(
|
210
|
+
await asyncio.wait_for(
|
211
|
+
waiting_event.wait(), timeout=self.commit_timeout
|
212
|
+
)
|
205
213
|
except asyncio.TimeoutError:
|
206
214
|
logger.warning("Took too much to commit")
|
215
|
+
raise TransactionCommitTimeoutError()
|
207
216
|
finally:
|
208
217
|
await self.stop_waiting(writer.kbid, request_id=request_id)
|
209
218
|
|
nucliadb_utils/utilities.py
CHANGED
@@ -265,6 +265,7 @@ async def start_transaction_utility(
|
|
265
265
|
transaction_utility = TransactionUtility(
|
266
266
|
nats_creds=transaction_settings.transaction_jetstream_auth,
|
267
267
|
nats_servers=transaction_settings.transaction_jetstream_servers,
|
268
|
+
commit_timeout=transaction_settings.transaction_commit_timeout,
|
268
269
|
)
|
269
270
|
await transaction_utility.initialize(service_name)
|
270
271
|
set_utility(Utility.TRANSACTION, transaction_utility)
|
{nucliadb_utils-2.46.1.post388.dist-info → nucliadb_utils-2.46.1.post390.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: nucliadb-utils
|
3
|
-
Version: 2.46.1.
|
3
|
+
Version: 2.46.1.post390
|
4
4
|
Home-page: https://nuclia.com
|
5
5
|
License: BSD
|
6
6
|
Classifier: Development Status :: 4 - Beta
|
@@ -21,8 +21,8 @@ Requires-Dist: nats-py[nkeys] >=2.6.0
|
|
21
21
|
Requires-Dist: pyjwt >=2.4.0
|
22
22
|
Requires-Dist: memorylru >=1.1.2
|
23
23
|
Requires-Dist: mrflagly
|
24
|
-
Requires-Dist: nucliadb-protos >=2.46.1.
|
25
|
-
Requires-Dist: nucliadb-telemetry >=2.46.1.
|
24
|
+
Requires-Dist: nucliadb-protos >=2.46.1.post390
|
25
|
+
Requires-Dist: nucliadb-telemetry >=2.46.1.post390
|
26
26
|
Provides-Extra: cache
|
27
27
|
Requires-Dist: redis >=4.3.4 ; extra == 'cache'
|
28
28
|
Requires-Dist: orjson >=3.6.7 ; extra == 'cache'
|
@@ -12,11 +12,11 @@ nucliadb_utils/nats.py,sha256=7hRKMflwxK-p_L0KFO5jibOGhzSw2F24mKvPG-A_iN8,8224
|
|
12
12
|
nucliadb_utils/partition.py,sha256=0tmXuwRM_v-OmKoRkB--OMDzomVEkmgxqMmNNomI_24,1173
|
13
13
|
nucliadb_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
nucliadb_utils/run.py,sha256=bKMfsPEK6WdWfiPyWPUxCqcLo4tq6eOwyaf910TOwBk,1713
|
15
|
-
nucliadb_utils/settings.py,sha256=
|
15
|
+
nucliadb_utils/settings.py,sha256=rRG1w5QsvsToVSZxOY6Rh1R0kxJUx_b-REsCK715T0I,7213
|
16
16
|
nucliadb_utils/signals.py,sha256=KxV4UUNWf4wrEbt1iJzy6PxYuTEhi6IRisKlYlq5OtM,2702
|
17
17
|
nucliadb_utils/store.py,sha256=kQ35HemE0v4_Qg6xVqNIJi8vSFAYQtwI3rDtMsNy62Y,890
|
18
|
-
nucliadb_utils/transaction.py,sha256=
|
19
|
-
nucliadb_utils/utilities.py,sha256
|
18
|
+
nucliadb_utils/transaction.py,sha256=CQpsuF-E2omh4gGMxXCn0dv7vL9ctxooWpSgWGbGfBA,7212
|
19
|
+
nucliadb_utils/utilities.py,sha256=-j-um6vUQvN0s-G5nJ7lGlj7TNjoVVBr4lwdujBQBHQ,13979
|
20
20
|
nucliadb_utils/audit/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
|
21
21
|
nucliadb_utils/audit/audit.py,sha256=v-e9R4hc6iVjtN2JeZk1MAhV5x_OC5s59uSv-kF3qFk,2698
|
22
22
|
nucliadb_utils/audit/basic.py,sha256=grlJpq5Z2LSkwgxY3PaaLb9e8asuevMPOgrzG1UcUDI,3267
|
@@ -56,15 +56,15 @@ nucliadb_utils/tests/unit/test_nats.py,sha256=4lLQOucQGwL9lubTfNFqXhXtua9u4lTlWj
|
|
56
56
|
nucliadb_utils/tests/unit/test_run.py,sha256=VHeojVBj_AfV_uNch9eEi4zCT-O94VKjwb_O-UZgqpA,1910
|
57
57
|
nucliadb_utils/tests/unit/test_signals.py,sha256=Br3BjBZpAtKPqeSmfHSGf1Seu4mB2OBWFCgLcNEH0PQ,2647
|
58
58
|
nucliadb_utils/tests/unit/test_tests.py,sha256=-YHgVMKJr_3WYwrBj9TnwpVLIkP80PLZpWnvAIYvnz8,1189
|
59
|
-
nucliadb_utils/tests/unit/test_transaction.py,sha256=
|
59
|
+
nucliadb_utils/tests/unit/test_transaction.py,sha256=ULVALWbMWEkH2Gq5Q8olEL8k8Kqyh5RAe0Lp9qdF1V4,3917
|
60
60
|
nucliadb_utils/tests/unit/test_utilities.py,sha256=uzSFm7HzHGU-PS4-dqjFQxyxgypNAvwKEm0PtBg6Wmg,5099
|
61
61
|
nucliadb_utils/tests/unit/storages/__init__.py,sha256=itSI7dtTwFP55YMX4iK7JzdMHS5CQVUiB1XzQu4UBh8,833
|
62
62
|
nucliadb_utils/tests/unit/storages/test_aws.py,sha256=GCsB_jwCUNV3Ogt8TZZEmNKAHvOlR0HGU7blrFbtJqs,1924
|
63
63
|
nucliadb_utils/tests/unit/storages/test_gcs.py,sha256=2XzJwgNpfjVGjtE-QdZhu3ayuT1EMEXINdM-_SatPCY,3554
|
64
64
|
nucliadb_utils/tests/unit/storages/test_pg.py,sha256=sJfUttMSzq8W1XYolAUcMxl_R5HcEzb5fpCklPeMJiY,17000
|
65
65
|
nucliadb_utils/tests/unit/storages/test_storage.py,sha256=VFpRq6Q6BjnIrBQCumYzR8DQUacwhxt5CzTKSlqqD24,6892
|
66
|
-
nucliadb_utils-2.46.1.
|
67
|
-
nucliadb_utils-2.46.1.
|
68
|
-
nucliadb_utils-2.46.1.
|
69
|
-
nucliadb_utils-2.46.1.
|
70
|
-
nucliadb_utils-2.46.1.
|
66
|
+
nucliadb_utils-2.46.1.post390.dist-info/METADATA,sha256=Ho91jRfMOwhC3OCEDzgb9XwEKLJgKrItfLnx8y0_d3o,1978
|
67
|
+
nucliadb_utils-2.46.1.post390.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
68
|
+
nucliadb_utils-2.46.1.post390.dist-info/top_level.txt,sha256=fE3vJtALTfgh7bcAWcNhcfXkNPp_eVVpbKK-2IYua3E,15
|
69
|
+
nucliadb_utils-2.46.1.post390.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
70
|
+
nucliadb_utils-2.46.1.post390.dist-info/RECORD,,
|
File without changes
|
{nucliadb_utils-2.46.1.post388.dist-info → nucliadb_utils-2.46.1.post390.dist-info}/top_level.txt
RENAMED
File without changes
|
{nucliadb_utils-2.46.1.post388.dist-info → nucliadb_utils-2.46.1.post390.dist-info}/zip-safe
RENAMED
File without changes
|