Skip to content

Commit 8d0b26f

Browse files
yzcj105weinbe58
andauthored
fix #1032 Exclusive Access: show validation error (#1035)
* Removing uneeded interface * WIP:exlcusive access class * WIP: saving results * exclusive access v1 * remove prints for debug * fix: status return code * status code "Submitted" -> Enqueued * refactor: enable saving and serialization and ExclusiveRemoteTask * refactor: comment out debug print statement in ExclusiveRemoteTask * refactor: streamline task status query logic and remove unused geometry field * use dataclass for ExclusiveCustomRemoteTask * refactor: use black to clean up whitespace and improve code formatting in HTTPHandler and ExclusiveRemoteTask * clean up duplicated imports * fix: add missing newline for improved code readability * merge * add validation error message * black reformat --------- Co-authored-by: Phillip Weinberg <weinbe58@gmail.com>
1 parent 8a638ab commit 8d0b26f

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/bloqade/analog/task/exclusive.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def submit_task_via_zapier(
102102
else:
103103
print(f"HTTP request failed with status code: {response.status_code}")
104104
print("HTTP responce: ", response.text)
105-
return "Failed"
105+
return "HTTP Request Failed"
106106

107107
def query_task_status(self, task_id: str):
108108
response = request(
@@ -115,21 +115,39 @@ def query_task_status(self, task_id: str):
115115
},
116116
)
117117
if response.status_code != 200:
118-
return "Not Found"
118+
return "HTTP Request Failed."
119119
response_data = response.json()
120120
# Get "matched" from the response
121121
matches = response_data.get("matches", None)
122122
# The return is a list of dictionaries
123123
# Verify if the list contains only one element
124124
if matches is None:
125125
print("No task found with the given ID.")
126-
return "Failed"
126+
return "Task searching Failed"
127127
elif len(matches) > 1:
128128
print("Multiple tasks found with the given ID.")
129-
return "Failed"
129+
return "Task searching Failed"
130+
131+
record = matches[0]
130132

131133
# Extract the status from the first dictionary
132-
status = matches[0].get("status")
134+
status = record.get("status")
135+
136+
if status == "Failed validation":
137+
googledoc = record.get("resultsFileUrl")
138+
139+
# convert the preview URL to download URL
140+
googledoc = convert_preview_to_download(googledoc)
141+
res = get(googledoc)
142+
res.raise_for_status()
143+
data = res.json()
144+
# get the "statusCode" and "message" from the data and print them out.
145+
status_code = data.get("statusCode", "NA")
146+
message = data.get("message", "NA")
147+
print(
148+
f"Task validation failed with status code: {status_code}, message: {message}"
149+
)
150+
133151
return status
134152

135153
def fetch_results(self, task_id: str):
@@ -283,7 +301,10 @@ def status(self) -> QuEraTaskStatusCode:
283301
return QuEraTaskStatusCode.Unsubmitted
284302
res = self._http_handler.query_task_status(self._task_id)
285303
if res == "Failed":
286-
raise ValueError("Query task status failed.")
304+
return QuEraTaskStatusCode.Failed
305+
elif res == "Failed validation":
306+
307+
return QuEraTaskStatusCode.Failed
287308
elif res == "Submitted":
288309
return QuEraTaskStatusCode.Enqueued
289310
# TODO: please add all possible status

0 commit comments

Comments
 (0)