rename to smartpack n smartunpack
This commit is contained in:
@@ -372,7 +372,7 @@ def _build_payload(
|
||||
}
|
||||
|
||||
|
||||
async def smartsend(
|
||||
async def smartpack(
|
||||
subject: str,
|
||||
data: List[Tuple[str, Any, str]],
|
||||
broker_url: str = DEFAULT_BROKER_URL,
|
||||
@@ -429,7 +429,7 @@ async def smartsend(
|
||||
Example:
|
||||
>>> # Send a single payload (still wrapped in a list)
|
||||
>>> data = {"key": "value"}
|
||||
>>> env, env_json_str = await smartsend(
|
||||
>>> env, env_json_str = await smartpack(
|
||||
... "my.subject",
|
||||
... [("dataname1", data, "dictionary")]
|
||||
... )
|
||||
@@ -444,7 +444,7 @@ async def smartsend(
|
||||
if sender_id is None:
|
||||
sender_id = str(uuid.uuid4())
|
||||
|
||||
log_trace(correlation_id, f"Starting smartsend for subject: {subject}")
|
||||
log_trace(correlation_id, f"Starting smartpack for subject: {subject}")
|
||||
|
||||
# Process payloads
|
||||
payloads = []
|
||||
@@ -494,7 +494,7 @@ async def smartsend(
|
||||
return env, env_json_str
|
||||
|
||||
|
||||
async def smartreceive(
|
||||
async def smartunpack(
|
||||
msg: Any,
|
||||
fileserver_download_handler: Callable = fetch_with_backoff,
|
||||
max_retries: int = 5,
|
||||
@@ -521,10 +521,10 @@ async def smartreceive(
|
||||
|
||||
Example:
|
||||
>>> # Receive from JSON string directly
|
||||
>>> env = await smartreceive(json_string)
|
||||
>>> env = await smartunpack(json_string)
|
||||
>>>
|
||||
>>> # Receive from transport message object (e.g., NATS, MQTT)
|
||||
>>> env = await smartreceive(nats_msg, fileserver_download_handler=fetch_with_backoff)
|
||||
>>> env = await smartunpack(nats_msg, fileserver_download_handler=fetch_with_backoff)
|
||||
>>> # env is a Dict with "payloads" key containing List[Tuple[str, Any, str]]
|
||||
>>> for dataname, data, type_ in env["payloads"]:
|
||||
>>> print(f"{dataname}: {data} (type: {type_})")
|
||||
@@ -623,7 +623,7 @@ class msghandler:
|
||||
self.broker_url = broker_url or self.DEFAULT_BROKER_URL
|
||||
self.fileserver_url = fileserver_url or self.DEFAULT_FILESERVER_URL
|
||||
|
||||
async def smartsend(
|
||||
async def smartpack(
|
||||
self,
|
||||
subject: str,
|
||||
data: List[Tuple[str, Any, str]],
|
||||
@@ -635,16 +635,16 @@ class msghandler:
|
||||
Args:
|
||||
subject: Subject/topic to send to
|
||||
data: List of (dataname, data, type) tuples
|
||||
**kwargs: Additional options passed to smartsend
|
||||
**kwargs: Additional options passed to smartpack
|
||||
|
||||
Returns:
|
||||
Tuple of (env, env_json_str)
|
||||
"""
|
||||
kwargs['broker_url'] = kwargs.get('broker_url', self.broker_url)
|
||||
kwargs['fileserver_url'] = kwargs.get('fileserver_url', self.fileserver_url)
|
||||
return await smartsend(subject, data, **kwargs)
|
||||
return await smartpack(subject, data, **kwargs)
|
||||
|
||||
async def smartreceive(
|
||||
async def smartunpack(
|
||||
self,
|
||||
msg: Any,
|
||||
**kwargs
|
||||
@@ -654,12 +654,12 @@ class msghandler:
|
||||
|
||||
Args:
|
||||
msg: Message to process
|
||||
**kwargs: Additional options passed to smartreceive
|
||||
**kwargs: Additional options passed to smartunpack
|
||||
|
||||
Returns:
|
||||
Dict with envelope metadata and payloads
|
||||
"""
|
||||
return await smartreceive(msg, **kwargs)
|
||||
return await smartunpack(msg, **kwargs)
|
||||
|
||||
|
||||
# Convenience functions for module-level usage
|
||||
@@ -679,7 +679,7 @@ def send(
|
||||
Returns:
|
||||
Tuple of (env, env_json_str)
|
||||
"""
|
||||
return asyncio.run(smartsend(subject, data, **kwargs))
|
||||
return asyncio.run(smartpack(subject, data, **kwargs))
|
||||
|
||||
|
||||
def receive(
|
||||
@@ -696,12 +696,12 @@ def receive(
|
||||
Returns:
|
||||
Dict with envelope metadata and payloads
|
||||
"""
|
||||
return asyncio.run(smartreceive(msg, **kwargs))
|
||||
return asyncio.run(smartunpack(msg, **kwargs))
|
||||
|
||||
|
||||
__all__ = [
|
||||
'smartsend',
|
||||
'smartreceive',
|
||||
'smartpack',
|
||||
'smartunpack',
|
||||
'plik_oneshot_upload',
|
||||
'fetch_with_backoff',
|
||||
'msghandler',
|
||||
|
||||
Reference in New Issue
Block a user