Skip to content

Commit

Permalink
Improve/fix logs
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Jan 3, 2025
1 parent 24a19bb commit 0a46e0e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions osf/management/commands/check_crossref_dois.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def check_crossref_dois(dry_run=True):
for preprint in preprint_batch:
doi_prefix = preprint.provider.doi_prefix
if not doi_prefix:
sentry.log_message(f'Preprint {preprint._id} has been skipped for CrossRef DOI Check since the '
f'provider {preprint.provider._id.name} has invalid `doi_prefix` {doi_prefix}')
sentry.log_message(f'Preprint [_id={preprint._id}] has been skipped for CrossRef DOI Check '
f'since the provider [_id={preprint.provider._id}] has invalid DOI Prefix '
f'[doi_prefix={doi_prefix}]')
continue
pending_dois.append(f'doi:{settings.DOI_FORMAT.format(prefix=doi_prefix, guid=preprint._id)}')

Expand All @@ -78,7 +79,7 @@ def check_crossref_dois(dry_run=True):
resp = requests.get(url)
resp.raise_for_status()
except requests.exceptions.HTTPError as exc:
logger.error(f'Could not contact crossref to check for DOIs, response returned with exception {exc}')
sentry.log_message(f'Could not contact crossref to check for DOIs, response returned with exception {exc}')
continue

preprints_response = resp.json()['message']['items']
Expand All @@ -87,19 +88,20 @@ def check_crossref_dois(dry_run=True):
preprint__id = preprint['DOI'].split('/')[-1]
base_guid, version = Guid.split_guid(preprint__id)
if not base_guid or not version:
sentry.log_message(f'Preprint._id {preprint__id} returned by CrossRef API is invalid')
sentry.log_message(f'[Skipped] Preprint [_id={preprint__id}] returned by CrossRef API has invalid _id')
continue
pending_preprint = preprints_with_pending_dois.filter(
versioned_guids__guid___id=base_guid,
versioned_guids__version=version,
).first()
if not pending_preprint:
sentry.log_message(f'Preprint._id {preprint__id} returned by CrossRef API is not found.')
sentry.log_message(f'[Skipped] Preprint [_id={preprint__id}] returned by CrossRef API is not found.')
continue
if not dry_run:
logger.debug(f'Set identifier for {pending_preprint._id}')
pending_preprint.set_identifier_values(preprint['DOI'], save=True)
else:
logger.info('DRY RUN')
logger.info(f'DRY RUN: Set identifier for {pending_preprint._id}')


def report_stuck_dois(dry_run=True):
Expand Down

0 comments on commit 0a46e0e

Please sign in to comment.