Skip to content

Commit 6678b50

Browse files
authored
Merge pull request #4039 from OpenNeuroOrg/access-tag-tasks
refactor(worker): Set access tags in broker tasks
2 parents 1bb432f + feda1f0 commit 6678b50

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

services/datalad/datalad_service/tasks/publish.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def create_remotes_and_export(dataset_path, public=False):
7575
await enableremote_tag_public(dataset_path)
7676
await export_dataset(dataset_path)
7777
if public:
78-
await set_s3_access_tag(os.path.basename(dataset_path), 'public')
78+
await set_s3_access_tag.kiq(os.path.basename(dataset_path))
7979

8080

8181
def create_remotes(dataset_path):
@@ -118,12 +118,8 @@ async def export_backup_and_drop(dataset_path):
118118
await s3_export(dataset_path, get_s3_remote(), tag.name)
119119
await fsck_and_drop(dataset_path, [tag.name for tag in tags])
120120
logger.info(f'Exporting/dropping tags for {dataset_id} complete')
121-
if public_dataset:
122-
logger.info(f'Setting public access tag for {dataset_id}')
123-
await set_s3_access_tag(dataset_id, 'public')
124-
else:
125-
logger.info(f'Setting private access tag for {dataset_id}')
126-
await set_s3_access_tag(dataset_id, 'private')
121+
logger.info(f'Queueing S3 access tag update for {dataset_id}')
122+
await set_s3_access_tag.kiq(dataset_id)
127123
logger.info(f'{dataset_id} export_backup_and_drop complete')
128124

129125

@@ -311,9 +307,15 @@ async def annex_drop(dataset_path, branches):
311307

312308

313309
async def set_remote_public(dataset_path):
314-
"""Configure x-amz-meta-access when a dataset is made public and update the S3 access tags."""
310+
"""
311+
Configure x-amz-meta-access when a dataset is made public and update the S3 access tags.
312+
313+
Used by scripts/tag-public.py and runs the tag tasks without the broker.
314+
"""
315315
await enableremote_tag_public(dataset_path)
316-
await set_s3_access_tag(os.path.basename(dataset_path), 'public')
316+
await asyncio.to_thread(
317+
set_s3_access_tag_worker, os.path.basename(dataset_path), 'public'
318+
)
317319

318320

319321
async def enableremote_tag_public(dataset_path):
@@ -370,8 +372,9 @@ def set_s3_access_tag_worker(dataset, value):
370372

371373

372374
@broker.task
373-
async def set_s3_access_tag(dataset, value='private'):
375+
async def set_s3_access_tag(dataset):
374376
"""Set access tag on all versions of all files."""
377+
value = 'public' if is_public_dataset(dataset) else 'private'
375378
loop = asyncio.get_running_loop()
376379
# Use the default executor for the orchestration task to avoid deadlocking
377380
# the tags_executor which is used for the sub-tasks.

services/datalad/tests/test_publish.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def test_export_snapshots(no_init_remote, client, new_dataset):
7575

7676

7777
@patch('datalad_service.tasks.publish.run_check', new_callable=AsyncMock)
78-
@patch('datalad_service.tasks.publish.set_s3_access_tag', new_callable=AsyncMock)
78+
@patch('datalad_service.tasks.publish.set_s3_access_tag_worker')
7979
async def test_set_remote_public(mock_set_s3_access_tag, mock_run_check, new_dataset):
8080
await set_remote_public(new_dataset.path)
8181

0 commit comments

Comments
 (0)