-
Notifications
You must be signed in to change notification settings - Fork 14
Add support for HS3 and SimpleAnalysis resource files #925
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4c01d50
global: add support for HS3 and SimpleAnalysis
GraemeWatt 4864056
opensearch: consolidate three 'if' conditions
GraemeWatt b748183
fixes: generalise add_simpleanalysis_analyses.py
GraemeWatt 5dc7c10
records: generalise is_simpleanalysis function
GraemeWatt 4a0db94
opensearch: endpoint URLs should start with 'http'
GraemeWatt 8e0a111
records: avoid deleting local files in JSON update
GraemeWatt b55a335
tests: remove comment addressed in commit 4c01d50
GraemeWatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import click | ||
| import logging | ||
|
|
||
| from celery import shared_task | ||
| from flask import current_app | ||
| from flask.cli import with_appcontext | ||
| from invenio_db import db | ||
|
|
||
| from hepdata.celery import dynamic_tasks | ||
| from hepdata.config import SIMPLEANALYSIS_FILE_TYPE, HS3_FILE_TYPE | ||
| from hepdata.cli import fix | ||
| from hepdata.ext.opensearch.api import reindex_batch | ||
| from hepdata.modules.submission.api import get_latest_hepsubmission | ||
| from hepdata.modules.submission.models import HEPSubmission | ||
| from hepdata.modules.records.utils.common import is_analysis | ||
|
|
||
| logging.basicConfig() | ||
| log = logging.getLogger(__name__) | ||
|
|
||
| @fix.command() | ||
| @with_appcontext | ||
| @click.option('--analyses-type', '-a', type=str, help=f"e.g. '{SIMPLEANALYSIS_FILE_TYPE}' or '{HS3_FILE_TYPE}'.") | ||
| @click.option('--batch-size', '-b', type=int, default=20, | ||
| help='Number of hepsubmission entries to check at a time.') | ||
| @click.option('--synchronous', '-s', type=bool, default=False) | ||
| def add_analyses(analyses_type, batch_size, synchronous=False): | ||
| """Check all submissions for resources with analyses_type in the description but not as the type.""" | ||
|
|
||
| if analyses_type not in (SIMPLEANALYSIS_FILE_TYPE, HS3_FILE_TYPE): | ||
| log.error(f"analyses-type must be '{SIMPLEANALYSIS_FILE_TYPE}' or '{HS3_FILE_TYPE}'") | ||
| return | ||
|
|
||
| all_ids = db.session.query(HEPSubmission.id).order_by(HEPSubmission.id).all() | ||
|
|
||
| count = 0 | ||
| total = len(all_ids) | ||
| while count < total: | ||
| batch_ids = [i[0] for i in all_ids[count:min(count + batch_size, total)]] | ||
| if synchronous: | ||
| _add_analyses_batch(analyses_type, batch_ids) | ||
| else: | ||
| log.info('Sending batch of IDs {0} to {1} to celery'.format(batch_ids[0], batch_ids[-1])) | ||
| dynamic_tasks.delay('_add_analyses_batch', 'add_analyses', analyses_type, batch_ids) | ||
| count += batch_size | ||
|
|
||
|
|
||
| @shared_task | ||
| def _add_analyses_batch(analyses_type, ids): | ||
| log.info(f"Checking for {analyses_type} resources in submission ids {ids}") | ||
| recids_to_reindex = [] | ||
| for id in ids: | ||
| hepsubmission = HEPSubmission.query.get(id) | ||
|
|
||
| if hepsubmission: | ||
| for resource in hepsubmission.resources: | ||
| if resource.file_type != analyses_type and is_analysis(analyses_type, resource.file_description): | ||
| log.info(f"Found {analyses_type} for resource {resource.file_location}") | ||
| # Update resource to have type analyses_type | ||
| resource.file_type = analyses_type | ||
| db.session.add(resource) | ||
| db.session.commit() | ||
|
|
||
| # Check if this is the latest finished submission - reindex if so | ||
| latest_submission = get_latest_hepsubmission(publication_recid=hepsubmission.publication_recid, overall_status='finished') | ||
| if latest_submission and latest_submission.version == hepsubmission.version: | ||
| recids_to_reindex.append(hepsubmission.id) | ||
|
|
||
| if recids_to_reindex: | ||
| recids_to_reindex = list(set(recids_to_reindex)) # remove duplicates before indexing | ||
| log.info(f"Reindexing records: {recids_to_reindex}") | ||
| reindex_batch(recids_to_reindex, current_app.config['OPENSEARCH_INDEX']) | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,4 +28,4 @@ | |
| and parsed by ``setup.py``. | ||
| """ | ||
|
|
||
| __version__ = "0.9.4dev20251013" | ||
| __version__ = "0.9.4dev20251015" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.