4
4
from framework .exceptions import HTTPError
5
5
from framework .celery_tasks import app as celery_app
6
6
from framework .postcommit_tasks .handlers import enqueue_postcommit_task , get_task_from_postcommit_queue
7
+ from website .identifiers .clients .exceptions import CrossRefUnavailableError
8
+ from website .settings import CROSSREF_UNAVAILABLE_DELAY
7
9
8
10
9
11
CROSSREF_FAIL_RETRY_DELAY = 12 * 60 * 60
@@ -68,6 +70,7 @@ def update_or_enqueue_on_preprint_updated(preprint_id, saved_fields=None):
68
70
@celery_app .task (bind = True , acks_late = True , max_retries = 5 , default_retry_delay = CROSSREF_FAIL_RETRY_DELAY )
69
71
def mint_doi_on_crossref_fail (self , preprint_id ):
70
72
from osf .models import Preprint
73
+
71
74
preprint = Preprint .load (preprint_id )
72
75
vg = preprint .versioned_guids .first ()
73
76
existing_versions_without_minted_doi = Preprint .objects .filter (
@@ -84,5 +87,9 @@ def mint_doi_on_crossref_fail(self, preprint_id):
84
87
self .retry ()
85
88
else :
86
89
crossref_client = preprint .get_doi_client ()
87
- if crossref_client :
88
- crossref_client .create_identifier (preprint , category = 'doi' , include_relation = False )
90
+ try :
91
+ if crossref_client :
92
+ crossref_client .create_identifier (preprint , category = 'doi' , include_relation = False )
93
+ except CrossRefUnavailableError as err :
94
+ logger .warning (f'CrossRef is unavailable during minting DOI on fail for preprint { preprint_id } . Error: { err .error } ' )
95
+ self .retry (countdown = CROSSREF_UNAVAILABLE_DELAY )
0 commit comments