88import pygit2
99import boto3
1010from github import Github
11- from taskiq_pipelines import Pipeline
1211
1312import datalad_service .common .s3
1413import datalad_service .common .github
@@ -63,14 +62,16 @@ def s3_sibling(dataset_path):
6362
6463
6564@broker .task
66- async def create_remotes_and_export (dataset_path ):
65+ async def create_remotes_and_export (dataset_path , public = False ):
6766 """
6867 Create public S3 and GitHub remotes and export to them.
6968
7069 Called by publish handler to make a dataset public initially.
7170 """
7271 create_remotes (dataset_path )
7372 await export_dataset (dataset_path )
73+ if public :
74+ await set_s3_access_tag (os .path .basename (dataset_path ), 'public' )
7475
7576
7677def create_remotes (dataset_path ):
@@ -79,6 +80,17 @@ def create_remotes(dataset_path):
7980 github_sibling (dataset_path , dataset )
8081
8182
83+ async def fsck_and_drop (dataset_path , branch ):
84+ # Check and clean local annexed files once export is complete
85+ fsck_success = await git_annex_fsck_remote (dataset_path , branch , get_s3_remote ())
86+ if fsck_success :
87+ logger .info (f'{ dataset_path } remote fsck passed for { branch } ' )
88+ await annex_drop (dataset_path , branch )
89+ logger .info (f'{ dataset_path } drop complete' )
90+ else :
91+ logger .error (f'{ dataset_path } remote fsck failed for { branch } ' )
92+
93+
8294@broker .task
8395async def export_backup_and_drop (dataset_path ):
8496 """
@@ -90,18 +102,7 @@ async def export_backup_and_drop(dataset_path):
90102 if tags :
91103 await s3_backup_push (dataset_path )
92104 for tag in tags :
93- # Check and clean local annexed files once export is complete
94- pipeline = Pipeline (broker , git_annex_fsck_remote ).call_next (
95- annex_drop ,
96- dataset_path = dataset_path ,
97- branch = tag .name ,
98- )
99- # Call the pipeline (arguments for git_annex_fsck_remote)
100- await pipeline .kiq (
101- dataset_path = dataset_path ,
102- branch = tag .name ,
103- remote = get_s3_remote (),
104- )
105+ await fsck_and_drop (dataset_path , tag .name )
105106
106107
107108@broker .task
@@ -137,17 +138,7 @@ async def export_dataset(
137138 # Drop cache once all exports are complete
138139 clear_dataset_cache (dataset_id )
139140 # Check and clean local annexed files once export is complete
140- pipeline = Pipeline (broker , git_annex_fsck_remote ).call_next (
141- annex_drop ,
142- dataset_path = dataset_path ,
143- branch = new_tag ,
144- )
145- # Call the pipeline (arguments for git_annex_fsck_remote)
146- await pipeline .kiq (
147- dataset_path ,
148- branch = new_tag , # Check the history from the new tag just exported
149- remote = get_s3_remote (),
150- )
141+ await fsck_and_drop (dataset_path , new_tag )
151142 else :
152143 # Clear the cache even if only sibling updates occurred
153144 clear_dataset_cache (dataset_id )
@@ -257,7 +248,7 @@ def monitor_remote_configs(dataset_path):
257248
258249
259250@broker .task
260- async def annex_drop (fsck_success , dataset_path , branch ):
251+ async def annex_drop (dataset_path , branch ):
261252 """Drop local contents from the annex."""
262253 # Ensure numcopies is set to 2 before running drop
263254 await run_check (['git-annex' , 'numcopies' , '2' ], dataset_path )
@@ -269,14 +260,11 @@ async def annex_drop(fsck_success, dataset_path, branch):
269260 # Not an issue if this fails
270261 pass
271262 # Drop will only drop successfully exported files present on both remotes
272- if fsck_success :
273- env = os .environ .copy ()
274- # Force git-annex to use cached credentials for this
275- del env ['AWS_ACCESS_KEY_ID' ]
276- del env ['AWS_SECRET_ACCESS_KEY' ]
277- await run_check (
278- ['git-annex' , 'drop' , '--branch' , branch ], dataset_path , env = env
279- )
263+ env = os .environ .copy ()
264+ # Force git-annex to use cached credentials for this
265+ del env ['AWS_ACCESS_KEY_ID' ]
266+ del env ['AWS_SECRET_ACCESS_KEY' ]
267+ await run_check (['git-annex' , 'drop' , '--branch' , branch ], dataset_path , env = env )
280268
281269
282270async def set_remote_public (dataset ):
0 commit comments