Skip to content

Commit

Permalink
Don't ingest a Zarr if nothing changed while uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Jul 6, 2022
1 parent 8b28039 commit 314046d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions dandi/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ def mkzarr() -> str:
yield {"status": "initiating upload", "size": total_size}
lgr.debug("%s: Beginning upload", asset_path)
bytes_uploaded = 0
need_ingest = False
upload_data = (
zarr_id,
client.get_url(f"/zarr/{zarr_id}/upload"),
Expand Down Expand Up @@ -991,6 +992,7 @@ def mkzarr() -> str:
)
for upspec in r
]
need_ingest = True
for fut in as_completed(futures):
try:
size = fut.result()
Expand Down Expand Up @@ -1024,14 +1026,16 @@ def mkzarr() -> str:
pluralize(len(old_zarr_files), "file"),
)
a.rmfiles(old_zarr_files, reingest=False)
lgr.debug("%s: Waiting for server to calculate Zarr checksum", asset_path)
yield {"status": "server calculating checksum"}
client.post(f"/zarr/{zarr_id}/ingest/")
while True:
sleep(2)
r = client.get(f"/zarr/{zarr_id}/")
if r["status"] == "Complete":
break
need_ingest = True
if need_ingest:
lgr.debug("%s: Waiting for server to calculate Zarr checksum", asset_path)
yield {"status": "server calculating checksum"}
client.post(f"/zarr/{zarr_id}/ingest/")
while True:
sleep(2)
r = client.get(f"/zarr/{zarr_id}/")
if r["status"] == "Complete":
break
lgr.info("%s: Asset successfully uploaded", asset_path)
yield {"status": "done", "asset": a}

Expand Down
2 changes: 2 additions & 0 deletions dandi/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def test_upload_zarr(new_dandiset: SampleDandiset) -> None:
assert isinstance(asset, RemoteZarrAsset)
assert asset.asset_type is AssetType.ZARR
assert asset.path == "sample.zarr"
# Test that uploading again without any changes works:
new_dandiset.upload()


def test_upload_different_zarr(tmp_path: Path, zarr_dandiset: SampleDandiset) -> None:
Expand Down

0 comments on commit 314046d

Please sign in to comment.