From 7f510760c01e6a0c4509d29dc5966ee5a2129f22 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Tue, 23 Aug 2022 10:41:40 -0400 Subject: [PATCH] 19413: Optimize reporting warnings to API server Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- sdk/cwl/arvados_cwl/executor.py | 58 +++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/sdk/cwl/arvados_cwl/executor.py b/sdk/cwl/arvados_cwl/executor.py index 3241fb607c..8635d5fcfe 100644 --- a/sdk/cwl/arvados_cwl/executor.py +++ b/sdk/cwl/arvados_cwl/executor.py @@ -252,6 +252,11 @@ The 'jobs' API is no longer supported. Called when there's a need to report errors, warnings or just activity statuses, for example in the RuntimeStatusLoggingHandler. """ + + if kind not in ('error', 'warning'): + # Ignore any other status kind + return + with self.workflow_eval_lock: current = None try: @@ -261,32 +266,35 @@ The 'jobs' API is no longer supported. if current is None: return runtime_status = current.get('runtime_status', {}) - if kind in ('error', 'warning'): - updatemessage = runtime_status.get(kind, "") - if not updatemessage: - updatemessage = message - - # Subsequent messages tacked on in detail - updatedetail = runtime_status.get(kind+'Detail', "") - maxlines = 40 - if updatedetail.count("\n") < maxlines: - if updatedetail: - updatedetail += "\n" - updatedetail += message + "\n" - - if detail: - updatedetail += detail + "\n" - - if updatedetail.count("\n") >= maxlines: - updatedetail += "\nSome messages may have been omitted. Check the full log." - - runtime_status.update({ - kind: updatemessage, - kind+'Detail': updatedetail, - }) - else: - # Ignore any other status kind + + original_updatemessage = updatemessage = runtime_status.get(kind, "") + if not updatemessage: + updatemessage = message + + # Subsequent messages tacked on in detail + original_updatedetail = updatedetail = runtime_status.get(kind+'Detail', "") + maxlines = 40 + if updatedetail.count("\n") < maxlines: + if updatedetail: + updatedetail += "\n" + updatedetail += message + "\n" + + if detail: + updatedetail += detail + "\n" + + if updatedetail.count("\n") >= maxlines: + updatedetail += "\nSome messages may have been omitted. Check the full log." + + if updatemessage == original_updatemessage and updatedetail == original_updatedetail: + # don't waste time doing an update if nothing changed + # (usually because we exceeded the max lines) return + + runtime_status.update({ + kind: updatemessage, + kind+'Detail': updatedetail, + }) + try: self.api.containers().update(uuid=current['uuid'], body={ -- 2.30.2