From 5b098ea6c0f72c46b91da0a0f1f97d523f63d656 Mon Sep 17 00:00:00 2001
From: Philip ABBET <philip.abbet@idiap.ch>
Date: Thu, 12 Oct 2017 10:03:29 +0200
Subject: [PATCH] Update error management in the WorkerController <-> Worker
 protocol

---
 beat/core/scripts/worker.py | 7 ++++++-
 beat/core/worker.py         | 4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/beat/core/scripts/worker.py b/beat/core/scripts/worker.py
index 5321dcde..24754d33 100755
--- a/beat/core/scripts/worker.py
+++ b/beat/core/scripts/worker.py
@@ -242,8 +242,12 @@ def main(user_input=None):
                 content = simplejson.dumps(result['result'])
                 logger.debug('send: """%s"""' % content.rstrip())
 
+                status = WorkerController.DONE
+                if result['result']['status'] != 0:
+                    status = WorkerController.JOB_ERROR
+
                 message = [
-                    WorkerController.DONE,
+                    status,
                     current_job_id,
                     content
                 ]
@@ -262,6 +266,7 @@ def main(user_input=None):
 
                 message = [
                     WorkerController.ERROR,
+                    current_job_id,
                     result['system_error']
                 ]
 
diff --git a/beat/core/worker.py b/beat/core/worker.py
index cd9fdcb8..e244bd20 100755
--- a/beat/core/worker.py
+++ b/beat/core/worker.py
@@ -139,6 +139,10 @@ class WorkerController(object):
                 job_id = int(data[0])
                 return (address, status, job_id, data[1:])
 
+            elif (status == WorkerController.ERROR) and (len(data) >= 2):
+                job_id = int(data[0])
+                return (address, status, job_id, data[1:])
+
             else:
                 job_id = None
                 return (address, status, job_id, data)
-- 
GitLab