From 8816501679ef9e6e23f6e973464cff8b665c642c Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Thu, 3 Oct 2019 15:50:12 +0200
Subject: [PATCH] return error when waiting and any subtask fails

---
 inventory_provider/tasks/worker.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py
index 35ad30ce..85e658db 100644
--- a/inventory_provider/tasks/worker.py
+++ b/inventory_provider/tasks/worker.py
@@ -509,10 +509,21 @@ def launch_refresh_cache_all(config):
 
 
 def _wait_for_tasks(task_ids, update_callback=lambda s: None):
+
+    all_successful = True
+
     start_time = time.time()
     while task_ids and time.time() - start_time < FINALIZER_TIMEOUT_S:
         update_callback('waiting for tasks to complete: %r' % task_ids)
         time.sleep(FINALIZER_POLLING_FREQUENCY_S)
+
+        def _is_error(id):
+            status = check_task_status(id)
+            return status['ready'] and not status['success']
+
+        if any([_is_error(id) for id in task_ids]):
+            all_successful = False
+
         task_ids = [
             id for id in task_ids
             if not check_task_status(id)['ready']
@@ -521,6 +532,9 @@ def _wait_for_tasks(task_ids, update_callback=lambda s: None):
     if task_ids:
         raise InventoryTaskError(
             'timeout waiting for pending tasks to complete')
+    if not all_successful:
+        raise InventoryTaskError(
+            'some tasks finished with an error')
 
     update_callback('pending taskscompleted in {} seconds'.format(
             time.time() - start_time))
-- 
GitLab