Repository navigation
[ENG-9044] Add manage command to resync preprint dois v1 #11617
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
base: feature/pbs-26-19
Are you sure you want to change the base?
Changes from all commits
abfc3c9
af27fef
8e93ef4
6efa09a
78ba103
03b77a5
ab09a25
88f467a
47798c1
9c4a270
71a3038
4895983
3a6ad34
140b15b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| from api.crossref.permissions import RequestComesFromMailgun | ||
| from osf.models import Preprint, NotificationTypeEnum | ||
| from osf.models.base import Guid | ||
| from website import settings | ||
| from website.preprints.tasks import mint_doi_on_crossref_fail | ||
|
|
||
|
|
@@ -48,6 +49,24 @@ def post(self, request): | |
| if record.get('status').lower() == 'success' and doi: | ||
| msg = record.find('msg').text | ||
| created = bool(msg == 'Successfully added') | ||
| # Unversioned DOIs (no _vN suffix, e.g. 10.31233/osf.io/tnaqp) are routing | ||
| # aliases that always resolve to the latest version via OSF's GUID routing. | ||
| # Store them as 'doi_unversioned' on the v1 preprint so we can track which | ||
| # preprint series have had their unversioned DOI registered. | ||
| _, version = Guid.split_guid(guid) if guid else (None, None) | ||
| if not version: | ||
| logger.info(f'Unversioned DOI confirmed by CrossRef: {doi}') | ||
| if guid: | ||
| v1_preprint = Preprint.objects.filter( | ||
| versioned_guids__guid___id=guid, | ||
| versioned_guids__version=1, | ||
| ).first() | ||
| if v1_preprint: | ||
| v1_preprint.set_identifier_value(category='doi_unversioned', value=doi) | ||
| Preprint.objects.filter(id=v1_preprint.id).update(doi_resync_queued_at=None) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR comment: Added doi_resync_queued_at, so not include them to eligible for resync |
||
| dois_processed += 1 | ||
| continue | ||
|
|
||
| legacy_doi = preprint.get_identifier(category='legacy_doi') | ||
| if created or legacy_doi: | ||
| # Sets preprint_doi_created and saves the preprint | ||
|
|
@@ -56,6 +75,7 @@ def post(self, request): | |
| elif 'possible preprint/vor pair' not in msg.lower(): | ||
| # Directly updates the identifier | ||
| preprint.set_identifier_value(category='doi', value=doi) | ||
| Preprint.objects.filter(id=preprint.id).update(doi_resync_queued_at=None) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR comment: set doi_resync_queued_at to None when preprint is being processed |
||
|
|
||
| dois_processed += 1 | ||
|
|
||
|
|
@@ -67,9 +87,14 @@ def post(self, request): | |
| if 'Relation target DOI does not exist' in record.find('msg').text: | ||
| logger.warning('Related publication DOI does not exist, sending metadata again without it...') | ||
| mint_doi_on_crossref_fail.apply_async(kwargs={'preprint_id': preprint._id}) | ||
| # This error occurs when a single preprint is being updated several times in a row with the same metadata [#PLAT-944] | ||
| elif 'less or equal to previously submitted version' in record.find('msg').text and record_count == 2: | ||
| break | ||
| # This error occurs when a single preprint is being updated several times in a row | ||
| # with the same metadata [#PLAT-944]. Previously this broke out of the loop when | ||
| # record_count == 2 (single DOI submitted twice). Now batches legitimately contain | ||
| # 2 records (versioned + unversioned DOI), so we continue instead of break to allow | ||
| # the remaining record to be processed. | ||
| elif 'less or equal to previously submitted version' in record.find('msg').text: | ||
| dois_processed += 1 | ||
| continue | ||
| else: | ||
| unexpected_errors = True | ||
| logger.info(f'Creation success email received from CrossRef for preprints: {guids}') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So a DOI in the
doi_unversionedcategory is only written when Crossref repliesSuccessfully added. This could be a potential issue because if the DOIis already registered, the email probably comes back with something like
Successfully updated, so for those preprintsthis branch never runs.
This would affect legacy preprints that exists before versioning was a thing. Their base guid is their original guid, so the DOI deposit here is the one registered years ago.
I checked against a local copy of prod db. One of preprint
22hq2has10.31219/osf.io/22hq2already registered with crossref. So it's possible that the crossref response email wouldn't containSuccessfully addedbutSuccessfully updatedor some other language. Will need to confirm if that is indeed the case.If that is the case, one possible fix is that for an unversioned DOI, store
doi_unversionedon any successful record rather than only onSuccessfully added.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another problem: if we run the resync task every five minutes, and if the preprint that was resynced in the last run still haven't received an email back confirming the update of the DOI, then in the next run it will be included in the resync task again. So we'd have to rethink how we should do this. One idea suggested by @cslzchen is that we follow the example in this PR and monitory the number of active tasks and spawn new tasks if the number of active task falls below a certain number (say 1000). In this case, we don't have to worry about running the task every five minutes.