Skip to content

Commit

Permalink
Correctly retry failed batch index updates
Browse files Browse the repository at this point in the history
Using retry doesn't work in celery-batches, it just raises the original
exception. See clokep/celery-batches#10

Fixes WEBLATE-FM
Fixes WEBLATE-FY
Fixes WEBLATE-FW
Fixes WEBLATE-FT
Fixes WEBLATE-FS
Fixes WEBLATE-FV
Fixes WEBLATE-FR

Signed-off-by: Michal Čihař <[email protected]>
  • Loading branch information
nijel committed Oct 9, 2018
1 parent 640e327 commit f112364
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Released on ? 2018.
* Fixed progress reporting for newly added languages.
* Correctly report Celery worker errors to Sentry.
* Fixed creating new translations with Qt Linguist.
* Fixed occasional fulltext index update failures.

weblate 3.2
------------
Expand Down
13 changes: 7 additions & 6 deletions weblate/memory/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ def update_memory(user, unit):
)


@app.task(
base=Batches, flush_every=1000, flush_interval=300, bind=True,
max_retries=1000
)
@app.task(base=Batches, flush_every=1000, flush_interval=300, bind=True)
def update_memory_task(self, *args, **kwargs):
def fixup_strings(data):
result = {}
Expand All @@ -101,8 +98,12 @@ def fixup_strings(data):
with memory.writer() as writer:
for item in data:
writer.add_document(**fixup_strings(item))
except LockError as exc:
raise self.retry(exc=exc)
except LockError:
# Manually handle retries, it doesn't work
# with celery-batches
sleep(10)
for unit in data:
update_memory_task.delay(**unit)


@app.task
Expand Down
27 changes: 15 additions & 12 deletions weblate/trans/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from __future__ import absolute_import, unicode_literals

import functools
from time import sleep

from celery_batches import Batches

Expand Down Expand Up @@ -250,25 +251,23 @@ def delete_search_units(self, source_units, languages):
writer.delete_by_term('pk', pk)


@app.task(
base=Batches, flush_every=1000, flush_interval=300, bind=True,
max_retries=1000
)
@app.task(base=Batches, flush_every=1000, flush_interval=300, bind=True)
def update_fulltext(self, *args, **kwargs):
unitdata = extract_batch_kwargs(*args, **kwargs)
fulltext = Fulltext()

# Update index
try:
fulltext.update_index(unitdata)
except LockError as exc:
raise self.retry(exc=exc)
except LockError:
# Manually handle retries, it doesn't work
# with celery-batches
sleep(10)
for unit in unitdata:
update_fulltext.delay(**unit)


@app.task(
base=Batches, flush_every=1000, flush_interval=300, bind=True,
max_retries=1000
)
@app.task(base=Batches, flush_every=1000, flush_interval=300, bind=True)
def delete_fulltext(self, *args):
ids = extract_batch_args(*args)
fulltext = Fulltext()
Expand All @@ -285,5 +284,9 @@ def delete_fulltext(self, *args):

try:
fulltext.delete_search_units(units, languages)
except LockError as exc:
raise self.retry(exc=exc)
except LockError:
# Manually handle retries, it doesn't work
# with celery-batches
sleep(10)
for unit in ids:
delete_fulltext.delay(*unit)

0 comments on commit f112364

Please sign in to comment.