|
6 | 6 |
|
7 | 7 | from deprecated import deprecated |
8 | 8 | from shapely.geometry import Polygon, MultiPolygon, mapping |
9 | | -from requests import ConnectionError |
10 | 9 |
|
11 | 10 | from openeo.graphbuilder import GraphBuilder |
12 | 11 | from openeo.imagecollection import ImageCollection, CollectionMetadata |
@@ -982,45 +981,9 @@ def execute_batch( |
982 | 981 | :param format_options: String Parameters for the job result format |
983 | 982 |
|
984 | 983 | """ |
985 | | - # TODO: move this logic to RESTJob? |
| 984 | + from openeo.rest.job import RESTJob |
986 | 985 | job = self.send_job(out_format,job_options=job_options, **format_options) |
987 | | - job.start_job() |
988 | | - |
989 | | - job_id = job.job_id |
990 | | - job_info = None |
991 | | - status = None |
992 | | - poll_interval = min(5, max_poll_interval) |
993 | | - start_time = time.time() |
994 | | - while True: |
995 | | - # TODO: also allow a hard time limit on this infinite poll loop? |
996 | | - elapsed = str(datetime.timedelta(seconds=time.time() - start_time)) |
997 | | - try: |
998 | | - job_info = job.describe_job() |
999 | | - except ConnectionError as e: |
1000 | | - print("{t} Connection error while querying job status: {e}".format(t=elapsed, e=e)) |
1001 | | - time.sleep(connection_retry_interval) |
1002 | | - continue |
1003 | | - |
1004 | | - status = job_info.get("status", "N/A") |
1005 | | - print("{t} Job {i}: {s} (progress {p})".format( |
1006 | | - t=elapsed, i=job_id, s=status, |
1007 | | - p='{p}%'.format(p=job_info["progress"]) if "progress" in job_info else "N/A" |
1008 | | - )) |
1009 | | - if status not in ('submitted', 'queued', 'running'): |
1010 | | - break |
1011 | | - |
1012 | | - time.sleep(poll_interval) |
1013 | | - poll_interval = min(1.25 * poll_interval, max_poll_interval) |
1014 | | - |
1015 | | - elapsed = str(datetime.timedelta(seconds=time.time() - start_time)) |
1016 | | - if status == 'finished': |
1017 | | - job.download_results(outputfile) |
1018 | | - else: |
1019 | | - raise RuntimeError("Batch job {i} didn't finish properly. Status: {s} (after {t}).".format( |
1020 | | - i=job_id, s=status, t=elapsed |
1021 | | - )) |
1022 | | - |
1023 | | - return job_info |
| 986 | + return RESTJob.run_synchronous(job,outputfile,print=print, max_poll_interval=60, connection_retry_interval=30) |
1024 | 987 |
|
1025 | 988 | def send_job(self, out_format=None, job_options=None, **format_options) -> Job: |
1026 | 989 | """ |
|
0 commit comments