Skip to content

Commit 5bfc8dd

Browse files
authored
Merge pull request #10268 from sbwhitt/fix/merge-authors
Add retry logic to author merge request status update
2 parents 37d059b + d169fc4 commit 5bfc8dd

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

openlibrary/plugins/upstream/merge_authors.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from openlibrary.plugins.upstream.edits import process_merge_request
1515
from openlibrary.plugins.worksearch.code import top_books_from_author
1616
from openlibrary.utils import dicthash, uniq
17+
from openlibrary.utils.retry import MaxRetriesExceeded, RetryStrategy
1718

1819

1920
class BasicRedirectEngine:
@@ -366,9 +367,15 @@ def POST(self):
366367
comment = data.get('comment', None)
367368
olids = data.get('olids', '')
368369

369-
engine = AuthorMergeEngine(AuthorRedirectEngine())
370-
try:
371-
result = engine.merge(master, duplicates)
370+
def merge_records() -> Any:
371+
try:
372+
engine = AuthorMergeEngine(AuthorRedirectEngine())
373+
return engine.merge(master, duplicates)
374+
except ClientException as e:
375+
raise web.badrequest(json.loads(e.json))
376+
377+
def update_request() -> None:
378+
data = {}
372379
if mrid:
373380
# Update the request
374381
rtype = 'update-request'
@@ -380,9 +387,21 @@ def POST(self):
380387
if comment:
381388
data['comment'] = comment
382389
process_merge_request(rtype, data)
383-
except ClientException as e:
384-
raise web.badrequest(json.loads(e.json))
385-
return delegate.RawText(json.dumps(result), content_type="application/json")
390+
391+
# actually perform merge and save affected records to db
392+
merge_result = merge_records()
393+
# attempt to update the merge request status with retries
394+
try:
395+
RetryStrategy(
396+
[ClientException],
397+
max_retries=5,
398+
delay=2,
399+
)(update_request)
400+
except MaxRetriesExceeded as e:
401+
raise web.badrequest(str(e.last_exception))
402+
return delegate.RawText(
403+
json.dumps(merge_result), content_type="application/json"
404+
)
386405

387406

388407
def setup():

0 commit comments

Comments
 (0)