Repository: EdinburghGenomics/EGCG-Core

Issue:
Failure to register for archiving cause pipeline crash
We should make the registering for archiving more robust by sleeping trying again to register the file after 1 second.
https://github.com/EdinburghGenomics/EGCG-Core/blob/master/egcg_core/archive_management.py#L92
This raising can cause Analysis Driver to crash at the end of the processing rather randomly.


Discussion:

Patch:
diff --git a/egcg_core/archive_management.py b/egcg_core/archive_management.py
index 3437925..58c5eb9 100644
--- a/egcg_core/archive_management.py
+++ b/egcg_core/archive_management.py
@@ -1,6 +1,8 @@
 import os
 import re
 import subprocess
+from time import sleep
+
 from egcg_core.app_logging import logging_default as log_cfg
 from egcg_core.exceptions import EGCGError
 
@@ -83,13 +85,18 @@ def release_file_from_lustre(file_path):
         return True
 
 
-def register_for_archiving(file_path):
+def register_for_archiving(file_path, strict=False):
     if is_register_for_archiving(file_path):
         return True
     cmd = 'lfs hsm_archive %s' % file_path
     val = _get_stdout(cmd)
     if val is None or not is_register_for_archiving(file_path):
-        raise ArchivingError('Registering %s for archiving to tape failed' % file_path)
+        if strict:
+            raise ArchivingError('Registering %s for archiving to tape failed' % file_path)
+        # Registering for archive can sometime take time so give it a second
+        sleep(1)
+        return register_for_archiving(filter, strict=True)
+
     return True
 
 


Test patch:
diff --git a/tests/test_archive_management.py b/tests/test_archive_management.py
index c087706..5d45646 100644
--- a/tests/test_archive_management.py
+++ b/tests/test_archive_management.py
@@ -76,7 +76,7 @@ class TestArchiveManagement(TestEGCG):
                        '',
                        'testfile: (0x00000001)',
                     ]) as get_stdout:
-            self.assertRaises(ArchivingError, register_for_archiving, 'testfile')
+            self.assertRaises(ArchivingError, register_for_archiving, 'testfile', True)
             assert get_stdout.call_count == 3
             assert get_stdout.call_args_list[1][0] == ('lfs hsm_archive testfile',)