From ade7f58ebaed05d9488094f1637af4ef54382f29 Mon Sep 17 00:00:00 2001 From: yashsinghcodes Date: Tue, 21 Jan 2025 03:00:12 +0530 Subject: [PATCH 1/2] handle shuffle_auto_remove condition and added a size result size limit --- shuffle_sdk/shuffle_sdk.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/shuffle_sdk/shuffle_sdk.py b/shuffle_sdk/shuffle_sdk.py index 610e8b2..6be92f7 100755 --- a/shuffle_sdk/shuffle_sdk.py +++ b/shuffle_sdk/shuffle_sdk.py @@ -685,7 +685,21 @@ def send_result(self, action_result, headers, stream_path): if not "User-Agent" in headers: headers["User-Agent"] = "Shuffle App" + try: + #self.logger.info(f"[INFO] Size of result: {len(json.dumps(action_result['result']).encode('utf-8'))}") + json_size = len(json.dumps(action_result["result"]).encode('utf-8')) + + # 20MB limit + if json_size > 20000000: + action_result["status"] = "FAILURE" + action_result["result"] = json.dumps({"success": False, "reason": "Result too large to send to backend. Size: %d bytes" % json_size}) + + except Exception as e: + self.logger.info(f"[ERROR] Failed to get size of result: {e}") + + self.logger.info(f"[DEBUG][{self.current_execution_id}] Starting to send result to {url}") + try: finished = False ret = {} @@ -2008,13 +2022,9 @@ def execute_action(self, action): try: if replace_params == True: for inner_action in self.full_execution["workflow"]["actions"]: - self.logger.info("[DEBUG] ID: %s vs %s" % (inner_action["id"], self.action["id"])) # In case of some kind of magic, we're just doing params - if inner_action["id"] != self.action["id"]: - continue - self.logger.info("FOUND!") - + if inner_action["id"] == self.action["id"]: if isinstance(self.action, str): self.logger.info("Params is in string object for self.action?") else: From f02698b7bd13eabe39089e21703ba61c7e646d17 Mon Sep 17 00:00:00 2001 From: yashsinghcodes Date: Tue, 21 Jan 2025 04:03:39 +0530 Subject: [PATCH 2/2] better failer reason --- shuffle_sdk/shuffle_sdk.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/shuffle_sdk/shuffle_sdk.py b/shuffle_sdk/shuffle_sdk.py index 6be92f7..7c6700d 100755 --- a/shuffle_sdk/shuffle_sdk.py +++ b/shuffle_sdk/shuffle_sdk.py @@ -688,12 +688,10 @@ def send_result(self, action_result, headers, stream_path): try: #self.logger.info(f"[INFO] Size of result: {len(json.dumps(action_result['result']).encode('utf-8'))}") json_size = len(json.dumps(action_result["result"]).encode('utf-8')) - # 20MB limit if json_size > 20000000: action_result["status"] = "FAILURE" - action_result["result"] = json.dumps({"success": False, "reason": "Result too large to send to backend. Size: %d bytes" % json_size}) - + action_result["result"] = json.dumps({"success": False, "reason": "Result too large to send to backend. Size: %d MB. Max: 20MB" % (json_size//(1024*1024))}) except Exception as e: self.logger.info(f"[ERROR] Failed to get size of result: {e}") @@ -2022,7 +2020,6 @@ def execute_action(self, action): try: if replace_params == True: for inner_action in self.full_execution["workflow"]["actions"]: - # In case of some kind of magic, we're just doing params if inner_action["id"] == self.action["id"]: if isinstance(self.action, str):