From 1538aefced6650825813f6bcdbf4428d870cf9e5 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Wed, 18 May 2016 08:20:34 +0000
Subject: [PATCH] Task #8437: Do not send status twice when using
 runPipeline.sh

---
 CEP/Pipeline/framework/lofarpipe/support/control.py | 7 ++++++-
 CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl     | 3 +++
 MAC/Services/src/PipelineControl.py                 | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/CEP/Pipeline/framework/lofarpipe/support/control.py b/CEP/Pipeline/framework/lofarpipe/support/control.py
index fb5cf895006..b1a8c04462d 100644
--- a/CEP/Pipeline/framework/lofarpipe/support/control.py
+++ b/CEP/Pipeline/framework/lofarpipe/support/control.py
@@ -93,7 +93,7 @@ class control(StatefulRecipe):
         indicates failure.
         """
 
-        if self.feedback_method == "messagebus":
+        if self.feedback_method == "messagebus" and self.feedback_send_status:
           bus = messagebus.ToBus("lofar.task.feedback.state")
           msg = TaskFeedbackState(
             "lofarpipe.support.control",
@@ -134,6 +134,11 @@ class control(StatefulRecipe):
         except:
           self.feedback_method = "messagebus"
 
+        try:
+          self.feedbacK_send_status = self.config.getboolean('feedback', 'send_status')
+        except:
+          self.feedback_send_status = True
+
         if self.feedback_method == "messagebus" and not messagebus.MESSAGING_ENABLED:
           self.logger.error("Feedback over messagebus requested, but messagebus support is not enabled or functional")
           return 1
diff --git a/CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl b/CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl
index 00215f0ac8e..e8d8adae319 100644
--- a/CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl
+++ b/CEP/Pipeline/recipes/sip/pipeline.cfg.CEP4.tmpl
@@ -35,6 +35,9 @@ xml_stat_file = %(runtime_directory)s/%(job_name)s/logs/%(start_time)s/statistic
 #    none          Do NOT send feedback and status
 method = messagebus
 
+# Report final state on the message bus? (yes for CEP2 using "startPython.sh", no for CEP4 using "runPipeline.sh")
+send_status = no
+
 [remote]
 method = custom_cmdline
 globalfs = yes
diff --git a/MAC/Services/src/PipelineControl.py b/MAC/Services/src/PipelineControl.py
index c892dc53f1a..4405ab7e9f7 100755
--- a/MAC/Services/src/PipelineControl.py
+++ b/MAC/Services/src/PipelineControl.py
@@ -44,7 +44,7 @@ The execution chains are as follows:
 (runPipeline.sh)     -> Calls
                           - state <- [ACTIVE]
                           - getParset
-                          - (run pipeline) (which, for CEP2 compatibility, still calls state <- [FINISHED/ABORTED])
+                          - (run pipeline)
                           - state <- [COMPLETING]
                           - (wrap up)
                           - state <- [FINISHED]
-- 
GitLab