Skip to content

Commit

Permalink
Merge branch 'main' into image_collection
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Jun 30, 2024
2 parents a0a9543 + d056437 commit 9b582a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
8 changes: 5 additions & 3 deletions pytest_gee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import ee
import httplib2

from pytest_gee import utils
from deprecated.sphinx import deprecated
from ee.cli.utils import wait_for_task

__version__ = "0.3.4"
__author__ = "Pierrick Rambaud"
Expand Down Expand Up @@ -83,6 +83,7 @@ def init_ee_from_service_account():
)


@deprecated(version="0.3.5", reason="Use the vanilla GEE ``wait_for_task`` function instead.")
def wait(task: Union[ee.batch.Task, str], timeout: int = 5 * 60) -> str:
"""Wait until the selected process is finished or we reached timeout value.
Expand All @@ -95,4 +96,5 @@ def wait(task: Union[ee.batch.Task, str], timeout: int = 5 * 60) -> str:
"""
# just expose the utils function
# this is compulsory as wait is also needed in the utils module
return utils.wait(task, timeout)
task_id = task.id if isinstance(task, ee.batch.Task) else task
return wait_for_task(task_id, timeout, log_progress=False)
26 changes: 6 additions & 20 deletions pytest_gee/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"""
from __future__ import annotations

import time
from pathlib import Path, PurePosixPath
from typing import List, Optional, Union
from warnings import warn

import ee
import ee.data
from deprecated.sphinx import deprecated
from ee.cli.utils import wait_for_task


@deprecated(version="0.3.5", reason="Use the vanilla GEE ``wait_for_task`` function instead.")
def wait(task: Union[ee.batch.Task, str], timeout: int = 10 * 60) -> str:
"""Wait until the selected process is finished or we reached timeout value.
Expand All @@ -25,23 +26,8 @@ def wait(task: Union[ee.batch.Task, str], timeout: int = 10 * 60) -> str:
Returns:
the final state of the task
"""
# give 5 seconds of delay to GEE to make sure the task is created
time.sleep(5)

# init both the task object and the state
task = task if isinstance(task, ee.batch.Task) else get_task(task)
assert task is not None, "The task is not found"
state = "UNSUBMITTED"

# loop every 5s to check the task state. This is blocking the Python interpreter
start_time = time.time()
while state != "COMPLETED" and time.time() - start_time < timeout:
time.sleep(5)
state = task.status()["state"]
if state == "FAILED":
break

return state
task_id = task.id if isinstance(task, ee.batch.Task) else task
return wait_for_task(task_id, timeout, log_progress=False)


def get_task(task_descripsion: str) -> Optional[ee.batch.Task]:
Expand Down Expand Up @@ -120,7 +106,7 @@ def export_asset(

# launch the task and wait for the end of exportation
task.start()
wait(description)
wait_for_task(task.id, 10 * 60, False)

return PurePosixPath(asset_id)

Expand Down

0 comments on commit 9b582a8

Please sign in to comment.