Skip to content

Commit dffaa9a

Browse files
committed
check finished_processing boolean instead of status string when polling for completion
1 parent 79cb5b2 commit dffaa9a

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/sindri/sindri.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ def _get_circuit(self, circuit_id: str, include_verification_key: bool = False)
161161
raise Sindri.APIError("Received unexpected type for circuit detail response.")
162162
return response_json
163163

164-
def _get_circuit_status(
165-
self,
166-
circuit_id: str,
167-
) -> str:
164+
def _get_circuit_status(self, circuit_id: str) -> str:
165+
"""Hit the circuit_status API endpoint and validate the response. Do not print anything.
166+
This may raise `Sindri.APIError` if the response is invalid."""
167+
return self._get_circuit_finished_status(circuit_id)[1]
168+
169+
def _get_circuit_finished_status(self, circuit_id: str) -> Tuple[bool, str]:
168170
"""Hit the circuit_status API endpoint and validate the response. Do not print anything.
169171
This may raise `Sindri.APIError` if the response is invalid."""
170172
response_status_code, response_json = self._hit_api(
@@ -178,10 +180,11 @@ def _get_circuit_status(
178180
)
179181
if not isinstance(response_json, dict):
180182
raise Sindri.APIError("Received unexpected type for circuit status response.")
183+
finished_processing = response_json.get("finished_processing", False)
181184
status = response_json.get("status", "")
182185
if status == "":
183186
raise Sindri.APIError("Received unexpected type for circuit status response.")
184-
return status
187+
return finished_processing, status
185188

186189
def _get_proof(
187190
self,
@@ -212,10 +215,12 @@ def _get_proof(
212215
raise Sindri.APIError("Received unexpected type for proof detail response.")
213216
return response_json
214217

215-
def _get_proof_status(
216-
self,
217-
proof_id: str,
218-
) -> str:
218+
def _get_proof_status(self, proof_id: str) -> str:
219+
"""Hit the proof_status API endpoint and validate the response. Do not print anything.
220+
This may raise `Sindri.APIError` if the response is invalid."""
221+
return self._get_proof_finished_status(proof_id)[1]
222+
223+
def _get_proof_finished_status(self, proof_id: str) -> Tuple[bool, str]:
219224
"""Hit the proof_status API endpoint and validate the response. Do not print anything.
220225
This may raise `Sindri.APIError` if the response is invalid."""
221226
response_status_code, response_json = self._hit_api(
@@ -229,10 +234,11 @@ def _get_proof_status(
229234
)
230235
if not isinstance(response_json, dict):
231236
raise Sindri.APIError("Received unexpected type for proof status response.")
237+
finished_processing = response_json.get("finished_processing", False)
232238
status = response_json.get("status", "")
233239
if status == "":
234240
raise Sindri.APIError("Received unexpected type for proof status response.")
235-
return status
241+
return finished_processing, status
236242

237243
def _get_verbose_1_circuit_detail(self, circuit_detail: dict) -> dict:
238244
"""Return a slim circuit detail object for printing."""
@@ -437,12 +443,12 @@ def create_circuit(
437443
print(f" circuit_id: {circuit_id}")
438444

439445
if wait:
440-
# 2. Poll circuit detail until it has a status of Ready/Failed
446+
# 2. Poll circuit detail until it is finished processing
441447
if self.verbose_level > 0:
442-
print("Circuit: Poll until Ready/Failed")
448+
print("Circuit: Poll until Finished")
443449
for _ in range(self.max_polling_iterations):
444-
circuit_status = self._get_circuit_status(circuit_id)
445-
if circuit_status in ["Ready", "Failed"]:
450+
finished_processing, _ = self._get_circuit_finished_status(circuit_id)
451+
if finished_processing:
446452
break
447453
time.sleep(self.polling_interval_sec)
448454
else:
@@ -820,12 +826,12 @@ def prove_circuit(
820826
print(f" proof_id: {proof_id}")
821827

822828
if wait:
823-
# 2. Poll proof detail until it has a status of Ready/Failed
829+
# 2. Poll proof detail until it is finished processing
824830
if self.verbose_level > 0:
825-
print("Proof: Poll until Ready/Failed")
831+
print("Proof: Poll until Finished")
826832
for _ in range(self.max_polling_iterations):
827-
proof_status = self._get_proof_status(proof_id)
828-
if proof_status in ["Ready", "Failed"]:
833+
finished_processing, _ = self._get_proof_finished_status(proof_id)
834+
if finished_processing:
829835
break
830836
time.sleep(self.polling_interval_sec)
831837
else:

0 commit comments

Comments
 (0)