Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: wait for upload #80

Open
mwallschlaeger opened this issue Nov 27, 2024 · 0 comments
Open

Feature: wait for upload #80

mwallschlaeger opened this issue Nov 27, 2024 · 0 comments
Labels
enhancement New feature or request feature new features

Comments

@mwallschlaeger
Copy link
Contributor

mwallschlaeger commented Nov 27, 2024

Feature Description

when uploading datasets, geonodectl currently not returning the json or at least the pk of the created dataset(s). This is because uploads are implemented asynchronously through executionrequests endpoints. iT would be nice to have a parameter to follow the upload and wait until upload is finished using a function like

Proposed Solution

Something like:

def __wait_and_get_upload_pks__(execid: str, gnConf: GeonodeApiConf) -> int:
    """
    Wait for the upload to finish and retrieve the primary key (pk) of the upload.

    Args:
        execid (str): The ID of the execution.

    Returns:
        int: The primary key (pk) of the upload.

    Raises:
        SystemExit: If the upload fails or the pk ID cannot be found.
    """
    gn_execreq = gnExecutionRequest(gnConf)
    r_exec = gn_execreq.get(exec_id=execid, page_size=100)
    t = 0
    while r_exec["status"] != "finished" and r_exec["status"] != "failed":
        time.sleep(5)
        logging.info(f"waiting for data upload to finished ({t} secs) ...")
        r_exec = gn_execreq.get(exec_id=execid, page_size=100)
        t += 5

    if r_exec["status"] == "failed":
        logging.error("upload failed ...")
        logging.error(r_exec)
        sys.exit(1)

    logging.info("upload finished ...")
    pks = []
    for resource in r_exec["output_params"]["resources"]:
        pks.append(resource["id"])
    return pks
@mwallschlaeger mwallschlaeger added feature new features enhancement New feature or request labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature new features
Projects
None yet
Development

No branches or pull requests

1 participant