19744: Add exception handler and pass api client to summarizer
authorPeter Amstutz <peter.amstutz@curii.com>
Wed, 21 Feb 2024 21:40:41 +0000 (16:40 -0500)
committerPeter Amstutz <peter.amstutz@curii.com>
Wed, 21 Feb 2024 21:40:41 +0000 (16:40 -0500)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

sdk/cwl/arvados_cwl/arvcontainer.py
tools/crunchstat-summary/crunchstat_summary/summarizer.py

index b7ef13070a26e034a49d2123902896c29abad244..97b4e45225f47b42d40711da0224c80fc6889153 100644 (file)
@@ -534,11 +534,16 @@ class ArvadosContainer(JobBase):
             ).execute(num_retries=self.arvrunner.num_retries)
 
             if logc is not None:
-                summerizer = crunchstat_summary.summarizer.NewSummarizer(self.uuid)
-                summerizer.run()
-                with logc.open("usage_report.html", "wt") as mr:
-                    mr.write(summerizer.html_report())
-                logc.save()
+                try:
+                    summerizer = crunchstat_summary.summarizer.NewSummarizer(self.uuid, arv=self.arvrunner.api)
+                    summerizer.run()
+                    with logc.open("usage_report.html", "wt") as mr:
+                        mr.write(summerizer.html_report())
+                    logc.save()
+                except Exception as e:
+                    logger.error("%s unable to generate resource usage report",
+                                 self.arvrunner.label(self),
+                                 exc_info=(e if self.arvrunner.debug else False))
 
         except WorkflowException as e:
             # Only include a stack trace if in debug mode.
index 75d49095d99963cf90753fe7391895e648941b85..062be3a65a929b91bc818a01de915aafdb439596 100644 (file)
@@ -547,7 +547,7 @@ def NewSummarizer(process_or_uuid, **kwargs):
     else:
         uuid = process_or_uuid
         process = None
-        arv = arvados.api('v1')
+        arv = kwargs.get("arv") or arvados.api('v1')
 
     if '-dz642-' in uuid:
         if process is None:
@@ -682,7 +682,7 @@ class MultiSummarizer(object):
 class JobTreeSummarizer(MultiSummarizer):
     """Summarizes a job and all children listed in its components field."""
     def __init__(self, job, label=None, **kwargs):
-        arv = arvados.api('v1')
+        arv = kwargs.get("arv") or arvados.api('v1')
         label = label or job.get('name', job['uuid'])
         children = collections.OrderedDict()
         children[job['uuid']] = JobSummarizer(job, label=label, **kwargs)
@@ -726,7 +726,7 @@ class PipelineSummarizer(MultiSummarizer):
 
 class ContainerRequestTreeSummarizer(MultiSummarizer):
     def __init__(self, root, skip_child_jobs=False, **kwargs):
-        arv = arvados.api('v1')
+        arv = kwargs.get("arv") or arvados.api('v1')
 
         label = kwargs.pop('label', None) or root.get('name') or root['uuid']
         root['name'] = label