nucliadb-utils 6.4.0.post4167__py3-none-any.whl → 6.4.0.post4176__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/cache/nats.py +11 -7
- nucliadb_utils/cache/pubsub.py +6 -4
- nucliadb_utils/nats.py +10 -5
- nucliadb_utils/transaction.py +2 -2
- {nucliadb_utils-6.4.0.post4167.dist-info → nucliadb_utils-6.4.0.post4176.dist-info}/METADATA +3 -3
- {nucliadb_utils-6.4.0.post4167.dist-info → nucliadb_utils-6.4.0.post4176.dist-info}/RECORD +8 -8
- {nucliadb_utils-6.4.0.post4167.dist-info → nucliadb_utils-6.4.0.post4176.dist-info}/WHEEL +0 -0
- {nucliadb_utils-6.4.0.post4167.dist-info → nucliadb_utils-6.4.0.post4176.dist-info}/top_level.txt +0 -0
nucliadb_utils/cache/nats.py
CHANGED
@@ -23,7 +23,7 @@ import functools
|
|
23
23
|
import os
|
24
24
|
import uuid
|
25
25
|
from inspect import iscoroutinefunction
|
26
|
-
from typing import Dict, List, Optional
|
26
|
+
from typing import Dict, List, Optional, Union
|
27
27
|
|
28
28
|
import nats
|
29
29
|
import nats.errors
|
@@ -34,10 +34,14 @@ from nats.aio.subscription import Subscription
|
|
34
34
|
from nats.js.client import JetStreamContext
|
35
35
|
from nats.js.manager import JetStreamManager
|
36
36
|
|
37
|
-
from nucliadb_telemetry.jetstream import
|
37
|
+
from nucliadb_telemetry.jetstream import (
|
38
|
+
JetStreamContextTelemetry,
|
39
|
+
NatsClientTelemetry,
|
40
|
+
get_traced_jetstream,
|
41
|
+
get_traced_nats_client,
|
42
|
+
)
|
38
43
|
from nucliadb_utils import logger
|
39
44
|
from nucliadb_utils.cache.pubsub import Callback, PubSubDriver
|
40
|
-
from nucliadb_utils.nats import get_traced_jetstream
|
41
45
|
|
42
46
|
|
43
47
|
async def wait_for_it(future: asyncio.Future, msg):
|
@@ -47,7 +51,7 @@ async def wait_for_it(future: asyncio.Future, msg):
|
|
47
51
|
# Configuration Utility
|
48
52
|
|
49
53
|
|
50
|
-
class NatsPubsub(PubSubDriver):
|
54
|
+
class NatsPubsub(PubSubDriver[Msg]):
|
51
55
|
_jetstream = None
|
52
56
|
_jsm = None
|
53
57
|
_subscriptions: Dict[str, Subscription]
|
@@ -69,11 +73,11 @@ class NatsPubsub(PubSubDriver):
|
|
69
73
|
self._uuid = os.environ.get("HOSTNAME", uuid.uuid4().hex)
|
70
74
|
self.initialized = False
|
71
75
|
self.lock = asyncio.Lock()
|
72
|
-
self.nc = None
|
76
|
+
self.nc: Union[Client, NatsClientTelemetry, None] = None
|
73
77
|
self.user_credentials_file = user_credentials_file
|
74
78
|
|
75
79
|
@property
|
76
|
-
def jetstream(self) -> JetStreamContext:
|
80
|
+
def jetstream(self) -> Union[JetStreamContext, JetStreamContextTelemetry]:
|
77
81
|
if self.nc is None:
|
78
82
|
raise AttributeError("NC not initialized")
|
79
83
|
if self._jetstream is None:
|
@@ -201,7 +205,7 @@ class NatsPubsub(PubSubDriver):
|
|
201
205
|
else:
|
202
206
|
raise ErrConnectionClosed("Could not publish")
|
203
207
|
|
204
|
-
def parse(self, data: Msg):
|
208
|
+
def parse(self, data: Msg) -> bytes:
|
205
209
|
return data.data
|
206
210
|
|
207
211
|
|
nucliadb_utils/cache/pubsub.py
CHANGED
@@ -17,12 +17,14 @@
|
|
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
|
-
from typing import
|
20
|
+
from typing import Awaitable, Callable, Generic, Optional, TypeVar
|
21
21
|
|
22
|
-
|
22
|
+
T = TypeVar("T")
|
23
23
|
|
24
|
+
Callback = Callable[[T], Awaitable[None]]
|
24
25
|
|
25
|
-
|
26
|
+
|
27
|
+
class PubSubDriver(Generic[T]):
|
26
28
|
initialized: bool = False
|
27
29
|
async_callback: bool = False
|
28
30
|
|
@@ -47,5 +49,5 @@ class PubSubDriver:
|
|
47
49
|
):
|
48
50
|
raise NotImplementedError()
|
49
51
|
|
50
|
-
def parse(self, data:
|
52
|
+
def parse(self, data: T) -> bytes:
|
51
53
|
raise NotImplementedError()
|
nucliadb_utils/nats.py
CHANGED
@@ -21,7 +21,7 @@ import asyncio
|
|
21
21
|
import logging
|
22
22
|
import sys
|
23
23
|
import time
|
24
|
-
from functools import cached_property
|
24
|
+
from functools import cached_property, partial
|
25
25
|
from typing import Any, Awaitable, Callable, Optional, Union
|
26
26
|
|
27
27
|
import nats
|
@@ -348,13 +348,18 @@ class NatsConnectionManager:
|
|
348
348
|
durable: Optional[str] = None,
|
349
349
|
config: Optional[nats.js.api.ConsumerConfig] = None,
|
350
350
|
) -> JetStreamContext.PullSubscription:
|
351
|
+
wrapped_cb: Callable[[Msg], Awaitable[None]]
|
352
|
+
if isinstance(self.js, JetStreamContextTelemetry):
|
353
|
+
wrapped_cb = partial(self.js.trace_pull_subscriber_message, cb)
|
354
|
+
else:
|
355
|
+
wrapped_cb = cb
|
356
|
+
|
351
357
|
psub = await self.js.pull_subscribe(
|
352
358
|
subject,
|
353
|
-
durable=durable,
|
359
|
+
durable=durable,
|
354
360
|
stream=stream,
|
355
|
-
config=config,
|
361
|
+
config=config,
|
356
362
|
)
|
357
|
-
|
358
363
|
cancelled = asyncio.Event()
|
359
364
|
|
360
365
|
async def consume(psub: JetStreamContext.PullSubscription, subject: str):
|
@@ -372,7 +377,7 @@ class NatsConnectionManager:
|
|
372
377
|
self.pull_utilization_metrics.inc({"status": "waiting"}, received - start_wait)
|
373
378
|
|
374
379
|
for message in messages:
|
375
|
-
await
|
380
|
+
await wrapped_cb(message)
|
376
381
|
|
377
382
|
if self.pull_utilization_metrics:
|
378
383
|
processed = time.monotonic()
|
nucliadb_utils/transaction.py
CHANGED
@@ -143,8 +143,8 @@ class TransactionUtility:
|
|
143
143
|
) -> Optional[Event]:
|
144
144
|
action_type = self._get_notification_action_type()
|
145
145
|
|
146
|
-
def received(waiting_for: WaitFor, event: Event,
|
147
|
-
data = self.pubsub.parse(
|
146
|
+
def received(waiting_for: WaitFor, event: Event, msg: Any):
|
147
|
+
data = self.pubsub.parse(msg)
|
148
148
|
pb = Notification()
|
149
149
|
pb.ParseFromString(data)
|
150
150
|
if pb.uuid == waiting_for.uuid and pb.action == action_type:
|
{nucliadb_utils-6.4.0.post4167.dist-info → nucliadb_utils-6.4.0.post4176.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nucliadb_utils
|
3
|
-
Version: 6.4.0.
|
3
|
+
Version: 6.4.0.post4176
|
4
4
|
Summary: NucliaDB util library
|
5
5
|
Author-email: Nuclia <nucliadb@nuclia.com>
|
6
6
|
License: AGPL
|
@@ -27,8 +27,8 @@ Requires-Dist: nats-py[nkeys]>=2.6.0
|
|
27
27
|
Requires-Dist: PyNaCl
|
28
28
|
Requires-Dist: pyjwt>=2.4.0
|
29
29
|
Requires-Dist: mrflagly>=0.2.9
|
30
|
-
Requires-Dist: nucliadb-protos>=6.4.0.
|
31
|
-
Requires-Dist: nucliadb-telemetry>=6.4.0.
|
30
|
+
Requires-Dist: nucliadb-protos>=6.4.0.post4176
|
31
|
+
Requires-Dist: nucliadb-telemetry>=6.4.0.post4176
|
32
32
|
Provides-Extra: cache
|
33
33
|
Requires-Dist: redis>=4.3.4; extra == "cache"
|
34
34
|
Requires-Dist: orjson>=3.6.7; extra == "cache"
|
@@ -7,14 +7,14 @@ nucliadb_utils/exceptions.py,sha256=y_3wk77WLVUtdo-5FtbBsdSkCtK_DsJkdWb5BoPn3qo,
|
|
7
7
|
nucliadb_utils/featureflagging.py,sha256=SYqr31e0_NeOMx6dZgSiDO9VJiV6xxYhM_gWkk8ITTQ,2386
|
8
8
|
nucliadb_utils/grpc.py,sha256=apu0uePnkGHCAT7GRQ9YZfRYyFj26kJ440i8jitbM3U,3314
|
9
9
|
nucliadb_utils/helpers.py,sha256=nPw8yod3hP-pxq80VF8QC36s7ygSg0dBUdfI-LatvCs,1600
|
10
|
-
nucliadb_utils/nats.py,sha256=
|
10
|
+
nucliadb_utils/nats.py,sha256=uMs5dTaAplBuj0D0NFFmXGmobrnl4N3FzhCMa-YsnFc,16204
|
11
11
|
nucliadb_utils/partition.py,sha256=jBgy4Hu5Iwn4gjbPPcthSykwf-qNx-GcLAIwbzPd1d0,1157
|
12
12
|
nucliadb_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
nucliadb_utils/run.py,sha256=Es0_Bu5Yc-LWczvwL6gzWqSwC85RjDCk-0oFQAJi9g4,1827
|
14
14
|
nucliadb_utils/settings.py,sha256=RnGhEUvwv6faNqALiqDCivvzNOyyXVBflYh_37uNkow,8193
|
15
15
|
nucliadb_utils/signals.py,sha256=lo_Mk12NIX5Au--3H3WObvDOXq_OMurql2qiC2TnAao,2676
|
16
16
|
nucliadb_utils/store.py,sha256=kQ35HemE0v4_Qg6xVqNIJi8vSFAYQtwI3rDtMsNy62Y,890
|
17
|
-
nucliadb_utils/transaction.py,sha256=
|
17
|
+
nucliadb_utils/transaction.py,sha256=l3ZvrITYMnAs_fv1OOC-1nDZxWPG5qmbBhzvuC3DUzQ,8039
|
18
18
|
nucliadb_utils/utilities.py,sha256=w4nsdyiFgZVEq5aBhjzVg176UDJNxfhIEfDbEi8bJdA,15604
|
19
19
|
nucliadb_utils/aiopynecone/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
|
20
20
|
nucliadb_utils/aiopynecone/client.py,sha256=MPyHnDXwhukJr7U3CJh7BpsekfSuOkyM4g5b9LLtzc8,22941
|
@@ -26,8 +26,8 @@ nucliadb_utils/audit/basic.py,sha256=4NX3IkZtTM_F2jD9TGE8-1eoS-hc-_zWwFGYVahGNSs
|
|
26
26
|
nucliadb_utils/audit/stream.py,sha256=XEY4wRxEPdrwaBtepT2-4fmeNSaCcyhMf4sZjiJVA6A,17261
|
27
27
|
nucliadb_utils/cache/__init__.py,sha256=itSI7dtTwFP55YMX4iK7JzdMHS5CQVUiB1XzQu4UBh8,833
|
28
28
|
nucliadb_utils/cache/exceptions.py,sha256=Zu-O_-0-yctOEgoDGI92gPzWfBMRrpiAyESA62ld6MA,975
|
29
|
-
nucliadb_utils/cache/nats.py,sha256=
|
30
|
-
nucliadb_utils/cache/pubsub.py,sha256=
|
29
|
+
nucliadb_utils/cache/nats.py,sha256=3aV25374fsA_oOr9ZqLDxhNn700O7CIagJ-0Y-ojwqE,7294
|
30
|
+
nucliadb_utils/cache/pubsub.py,sha256=YvJHiEhDaMIPofgQRpGY1belN--pOPyfYO1wFTUclt4,1701
|
31
31
|
nucliadb_utils/cache/settings.py,sha256=WVeHOE6Re5i4k2hUHdFKfkoL4n83v_Z6UPBK6GHYb8g,1059
|
32
32
|
nucliadb_utils/encryption/__init__.py,sha256=oav6jFOTGgmIen88sdmy-bCK-uj1tyDt2hr7lB2YKik,2690
|
33
33
|
nucliadb_utils/encryption/settings.py,sha256=yF2AW6c_mu0yWbBn1grAERDAqDvKIpXqQnwD0OFmROI,1467
|
@@ -57,7 +57,7 @@ nucliadb_utils/tests/gcs.py,sha256=MBMzn_UHU5SU6iILuCsB5zU4umhNcaCw_MKrxZhwvOc,4
|
|
57
57
|
nucliadb_utils/tests/local.py,sha256=cxIfPrKuqs5Ef0nbrVYQQAH2mwc4E0iD9bC2sWegS-c,1934
|
58
58
|
nucliadb_utils/tests/nats.py,sha256=RWHjwqq5esuO7OFbP24yYX1cXnpPLcWJwDUdmwCpH28,1897
|
59
59
|
nucliadb_utils/tests/s3.py,sha256=DACUh3HvgH3BchKFZ9R7RFUzsrg3v9A-cxTcXx4nmvA,3734
|
60
|
-
nucliadb_utils-6.4.0.
|
61
|
-
nucliadb_utils-6.4.0.
|
62
|
-
nucliadb_utils-6.4.0.
|
63
|
-
nucliadb_utils-6.4.0.
|
60
|
+
nucliadb_utils-6.4.0.post4176.dist-info/METADATA,sha256=xc81R9dPXXlDQ26yTGi9u_XxsvpD9J4S8xavW7Snfs0,2205
|
61
|
+
nucliadb_utils-6.4.0.post4176.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
|
62
|
+
nucliadb_utils-6.4.0.post4176.dist-info/top_level.txt,sha256=fE3vJtALTfgh7bcAWcNhcfXkNPp_eVVpbKK-2IYua3E,15
|
63
|
+
nucliadb_utils-6.4.0.post4176.dist-info/RECORD,,
|
File without changes
|
{nucliadb_utils-6.4.0.post4167.dist-info → nucliadb_utils-6.4.0.post4176.dist-info}/top_level.txt
RENAMED
File without changes
|