← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:po-export-queue-upload-failures into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:po-export-queue-upload-failures into launchpad:master.

Commit message:
Handle translation export upload failures

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1998037 in Launchpad itself: "Translation download not working"
  https://bugs.launchpad.net/launchpad/+bug/1998037

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/433803

If a translation export fails to upload to the librarian (perhaps because it's enormous), then we should mark the export as failed, notify the requester, and move on with the next export request.  Otherwise we can end up blocking the export queue forever.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:po-export-queue-upload-failures into launchpad:master.
diff --git a/lib/lp/translations/doc/poexport-queue.rst b/lib/lp/translations/doc/poexport-queue.rst
index d057880..ff5297d 100644
--- a/lib/lp/translations/doc/poexport-queue.rst
+++ b/lib/lp/translations/doc/poexport-queue.rst
@@ -406,6 +406,42 @@ Two more email notifications were sent, we'd better get rid of them.
 
     >>> discard = pop_notifications()
 
+If uploading the exported file to the librarian fails, then we send failure
+notifications in the same way as we do if the export fails.
+
+    >>> export_request_set.addRequest(
+    ...     carlos, pofiles=[pofile], format=TranslationFileFormat.PO
+    ... )
+    >>> transaction.commit()
+    >>> with mock.patch.object(
+    ...     ExportResult, "upload", side_effect=Exception("librarian melted")
+    ... ):
+    ...     process_queue(transaction, logging.getLogger())
+    >>> test_emails = pop_notifications()
+    >>> len(test_emails)
+    2
+    >>> for email in test_emails:
+    ...     if "carlos@xxxxxxxxxxxxx" in email["to"]:
+    ...         print_emails(notifications=[email], decode=True)  # noqa
+    ...
+    From: ...
+    To: carlos@xxxxxxxxxxxxx
+    Subject: Launchpad translation download: ...
+    Hello Carlos Perelló Marín,
+    <BLANKLINE>
+    Launchpad encountered problems exporting the files you requested.
+    The Launchpad Translations team has been notified of this problem.
+    Please reply to this email for further assistance.
+    <BLANKLINE>
+    If you want to retry your request, you can do so at
+    <BLANKLINE>
+      http://translations.launchpad.../+export.
+    <BLANKLINE>
+    -- 
+    Automatic message from Launchpad.net.
+    <BLANKLINE>
+    ----------------------------------------
+
 Finally, if we try to do an export with an empty queue, we don't do
 anything:
 
diff --git a/lib/lp/translations/scripts/po_export_queue.py b/lib/lp/translations/scripts/po_export_queue.py
index 54f27a9..0a48ca0 100644
--- a/lib/lp/translations/scripts/po_export_queue.py
+++ b/lib/lp/translations/scripts/po_export_queue.py
@@ -431,7 +431,10 @@ def process_queue(transaction_manager, logger):
 
         # Almost done.  Now we can go back to using the primary database
         # where needed.
-        result.upload(logger=logger)
+        try:
+            result.upload(logger=logger)
+        except Exception:
+            result.addFailure()
         result.notify()
 
         request_set.removeRequest(request_ids)