fix race condition init/heudiconv
This commit is contained in:
parent
b67e0d1bad
commit
795ff1b709
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import pydicom as dicom
|
import pydicom as dicom
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
@ -340,6 +341,17 @@ def init_bids(
|
||||||
bids_project_repo.protectedbranches.create(data={"name": "convert/*"})
|
bids_project_repo.protectedbranches.create(data={"name": "convert/*"})
|
||||||
bids_project_repo.protectedbranches.create(data={"name": "dev"})
|
bids_project_repo.protectedbranches.create(data={"name": "dev"})
|
||||||
|
|
||||||
|
### avoid race conditions for first session pushed ###
|
||||||
|
### otherwise heudiconv starts before the remotes are configured
|
||||||
|
time.sleep(5) # wait for config pipeline to be created
|
||||||
|
while True:
|
||||||
|
pipelines = bids_project_repo.pipelines.list(all=True)
|
||||||
|
no_pipe = all(p.status in ["success", "failed"] for p in pipelines)
|
||||||
|
if no_pipe:
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
return bids_project_repo
|
||||||
|
|
||||||
|
|
||||||
def init_dicom_study(
|
def init_dicom_study(
|
||||||
dicom_study_ds: dlad.Dataset,
|
dicom_study_ds: dlad.Dataset,
|
||||||
|
|
@ -385,7 +397,7 @@ def extract_session_metas(dicom_session_ds: dlad.Dataset) -> dict:
|
||||||
except Exception as e: # TODO: what exception occurs when non-dicom ?
|
except Exception as e: # TODO: what exception occurs when non-dicom ?
|
||||||
continue
|
continue
|
||||||
metas = {k: str(getattr(dic, k)).replace("^", "/") for k in SESSION_META_KEYS}
|
metas = {k: str(getattr(dic, k)).replace("^", "/") for k in SESSION_META_KEYS}
|
||||||
metas["StudyDescriptionPath"] = metas["StudyDescription"].split('/')
|
metas["StudyDescriptionPath"] = metas["StudyDescription"].split("/")
|
||||||
# return at first dicom found
|
# return at first dicom found
|
||||||
return metas
|
return metas
|
||||||
raise InputError("no dicom found")
|
raise InputError("no dicom found")
|
||||||
|
|
@ -465,7 +477,7 @@ def export_to_s3(
|
||||||
# git-annex initremote remotename ...
|
# git-annex initremote remotename ...
|
||||||
remote_name = s3_url.hostname
|
remote_name = s3_url.hostname
|
||||||
s3_path = s3_url.path
|
s3_path = s3_url.path
|
||||||
if '{' in s3_path:
|
if "{" in s3_path:
|
||||||
s3_path = s3_path.format(**session_metas)
|
s3_path = s3_path.format(**session_metas)
|
||||||
_, bucket_name, *fileprefix = pathlib.Path(s3_path).parts
|
_, bucket_name, *fileprefix = pathlib.Path(s3_path).parts
|
||||||
fileprefix.append(session_metas["StudyInstanceUID"] + "/")
|
fileprefix.append(session_metas["StudyInstanceUID"] + "/")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue