Skip to content

Commit 4a05334

Browse files
committed
Add pull method to ExclusiveRemoteTask
1 parent e720eda commit 4a05334

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/bloqade/analog/task/exclusive.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import abc
33
import uuid
44
import re
5+
import time
56

67
from beartype.typing import Dict
78
from dataclasses import dataclass, field
@@ -245,12 +246,34 @@ def fetch(self):
245246

246247
return self
247248

248-
def pull(self):
249-
# Please avoid using this method, it's blocking and the waiting time is hours long
250-
# Throw an error saying this is not supported
251-
raise NotImplementedError(
252-
"Pulling is not supported. Please use fetch() instead."
253-
)
249+
250+
def pull(self,poll_interval:float=20):
251+
"""
252+
Blocking pull to get the task result.
253+
poll_interval is the time interval to poll the task status.
254+
Please ensure that it is relatively large, otherwise
255+
the server could get overloaded with queries.
256+
"""
257+
if self._task_result_ir.task_status is QuEraTaskStatusCode.Unsubmitted:
258+
raise ValueError("Task ID not found.")
259+
260+
if self._task_result_ir.task_status in [
261+
QuEraTaskStatusCode.Completed,
262+
QuEraTaskStatusCode.Partial,
263+
QuEraTaskStatusCode.Failed,
264+
QuEraTaskStatusCode.Unaccepted,
265+
QuEraTaskStatusCode.Cancelled,
266+
]:
267+
return self
268+
269+
status = self.status()
270+
if status in [QuEraTaskStatusCode.Completed, QuEraTaskStatusCode.Partial]:
271+
self._task_result_ir = self._http_handler.fetch_results(self._task_id)
272+
else:
273+
time.sleep(poll_interval)
274+
self.pull(poll_interval)
275+
276+
return self
254277

255278
def cancel(self):
256279
# This is not supported

0 commit comments

Comments
 (0)