Skip to content

Commit b6164e0

Browse files
committed
Update command
1 parent 1c049a4 commit b6164e0

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

osf/management/commands/resync_preprint_dois_v1.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
logger = logging.getLogger(__name__)
1313

14+
# 5-minute pause between rate-limit windows to avoid flooding the Crossref API
15+
# with too many deposit requests in a short period.
1416
RATE_LIMIT_SLEEP = 60 * 5
1517

18+
1619
def get_preprints_needing_v1_doi(provider_id=None):
1720
content_type = ContentType.objects.get_for_model(Preprint)
1821

@@ -43,7 +46,7 @@ def get_preprints_needing_v1_doi(provider_id=None):
4346
return qs
4447

4548

46-
def resync_preprint_dois_v1(dry_run=True, batch_size=0, rate_limit=100, provider_id=None):
49+
def resync_preprint_dois_v1(dry_run=True, batch_size=500, rate_limit=100, provider_id=None):
4750
preprints_to_update = get_preprints_needing_v1_doi(provider_id=provider_id)
4851

4952
total = preprints_to_update.count()
@@ -60,6 +63,7 @@ def resync_preprint_dois_v1(dry_run=True, batch_size=0, rate_limit=100, provider
6063

6164
queued = 0
6265
skipped = 0
66+
errored = 0
6367
for record_number, preprint in enumerate(preprints_iterable, 1):
6468
if not preprint.provider.doi_prefix:
6569
logger.warning(
@@ -78,13 +82,17 @@ def resync_preprint_dois_v1(dry_run=True, batch_size=0, rate_limit=100, provider
7882
logger.info(f'Rate limit reached at {record_number} preprints, sleeping {RATE_LIMIT_SLEEP}s')
7983
time.sleep(RATE_LIMIT_SLEEP)
8084

81-
async_request_identifier_update.apply_async(kwargs={'preprint_id': preprint._id})
82-
logger.info(f'Queued DOI resync for preprint {preprint._id}')
83-
queued += 1
85+
try:
86+
async_request_identifier_update.apply_async(kwargs={'preprint_id': preprint._id})
87+
logger.info(f'Queued DOI resync for preprint {preprint._id}')
88+
queued += 1
89+
except Exception:
90+
logger.exception(f'Failed to queue DOI resync for preprint {preprint._id}')
91+
errored += 1
8492

8593
logger.info(
8694
f'{"[DRY RUN] " if dry_run else ""}'
87-
f'Done: {queued} preprints queued, {skipped} skipped (no DOI prefix)'
95+
f'Done: {queued} preprints queued, {skipped} skipped (no DOI prefix), {errored} errored'
8896
)
8997

9098

@@ -101,8 +109,12 @@ def add_arguments(self, parser):
101109
'--batch_size',
102110
'-b',
103111
type=int,
104-
default=0,
105-
help='Maximum number of preprints to process (0 = no limit).',
112+
default=500,
113+
help=(
114+
'Maximum number of preprints to process per run (default: 500). '
115+
'The command processes the first N eligible preprints and exits; '
116+
're-run the command to continue with the next batch.'
117+
),
106118
)
107119
parser.add_argument(
108120
'--rate_limit',

0 commit comments

Comments
 (0)