update
This commit is contained in:
@@ -759,8 +759,8 @@ function smartreceive(
|
||||
error("Unknown transport type for payload '$dataname': $(transport)") # Throw error for unknown transport
|
||||
end
|
||||
end
|
||||
|
||||
return payloads_list # Return list of (dataname, data, data_type) tuples
|
||||
json_data["payloads"] = payloads_list
|
||||
return json_data # Return envelope with list of (dataname, data, data_type) tuples in payloads field
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -603,7 +603,7 @@ async function smartreceive(msg, options = {}) {
|
||||
* @param {number} options.baseDelay - Initial delay for exponential backoff in ms (default: 100)
|
||||
* @param {number} options.maxDelay - Maximum delay for exponential backoff in ms (default: 5000)
|
||||
*
|
||||
* @returns {Promise<Array>} - List of {dataname, data, type} objects
|
||||
* @returns {Promise<Object>} - Envelope dictionary with metadata and payloads field containing list of {dataname, data, type} objects
|
||||
*/
|
||||
const {
|
||||
fileserverDownloadHandler = _fetch_with_backoff,
|
||||
@@ -664,7 +664,10 @@ async function smartreceive(msg, options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
return payloads_list;
|
||||
// Replace payloads array with the processed list of {dataname, data, type} tuples
|
||||
json_data.payloads = payloads_list;
|
||||
|
||||
return json_data;
|
||||
}
|
||||
|
||||
// Export for Node.js
|
||||
|
||||
@@ -559,7 +559,7 @@ def smartsend(subject, data, nats_url=DEFAULT_NATS_URL, fileserver_url=DEFAULT_F
|
||||
|
||||
|
||||
def smartreceive(msg, fileserver_download_handler=_fetch_with_backoff, max_retries=5,
|
||||
base_delay=100, max_delay=5000):
|
||||
base_delay=100, max_delay=5000):
|
||||
"""Receive and process messages from NATS.
|
||||
|
||||
This function processes incoming NATS messages, handling both direct transport
|
||||
@@ -573,7 +573,7 @@ def smartreceive(msg, fileserver_download_handler=_fetch_with_backoff, max_retri
|
||||
max_delay: Maximum delay for exponential backoff in ms
|
||||
|
||||
Returns:
|
||||
list: List of (dataname, data, type) tuples
|
||||
dict: Envelope dictionary with metadata and 'payloads' field containing list of (dataname, data, type) tuples
|
||||
"""
|
||||
# Parse the JSON envelope
|
||||
json_data = msg if isinstance(msg, dict) else json.loads(msg)
|
||||
@@ -611,7 +611,7 @@ def smartreceive(msg, fileserver_download_handler=_fetch_with_backoff, max_retri
|
||||
# Extract download URL from the payload
|
||||
url = payload.get("data", "")
|
||||
log_trace(json_data.get("correlationId", ""),
|
||||
"Link transport - fetching '{}' from URL: {}".format(dataname, url))
|
||||
"Link transport - fetching '{}' from URL: {}".format(dataname, url))
|
||||
|
||||
# Fetch with exponential backoff
|
||||
downloaded_data = fileserver_download_handler(
|
||||
@@ -627,7 +627,10 @@ def smartreceive(msg, fileserver_download_handler=_fetch_with_backoff, max_retri
|
||||
else:
|
||||
raise ValueError("Unknown transport type for payload '{}': {}".format(dataname, transport))
|
||||
|
||||
return payloads_list
|
||||
# Replace payloads field with the processed list of (dataname, data, type) tuples
|
||||
json_data["payloads"] = payloads_list
|
||||
|
||||
return json_data
|
||||
|
||||
|
||||
# Utility functions
|
||||
|
||||
Reference in New Issue
Block a user