Repository: liampauling/flumine
Pull request #210 (2020-06-08 12:59:17)

incorrect event type passed to logging control
logging control error handling added


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index b767a9d..20f0a4a 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,17 @@
 Release History
 ---------------
 
+1.6.6 (2020-06-08)
++++++++++++++++++++
+
+**Improvements**
+
+- Error handling added to logging control
+
+**Bug Fixes**
+
+- Incorrect event type passed to log_control
+
 1.6.5 (2020-06-08)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 1310719..540209f 100644
--- a/flumine/__version__.py
+++ b/flumine/__version__.py
@@ -1,6 +1,6 @@
 __title__ = "flumine"
 __description__ = "Betfair trading framework"
 __url__ = "https://github.com/liampauling/flumine"
-__version__ = "1.6.5"
+__version__ = "1.6.6"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/controls/loggingcontrols.py b/flumine/controls/loggingcontrols.py
index ddf2789..ec686bf 100644
--- a/flumine/controls/loggingcontrols.py
+++ b/flumine/controls/loggingcontrols.py
@@ -33,7 +33,14 @@ class LoggingControl(Thread):
                 logger.info("Shutting down logging control %s" % self.NAME)
                 break
             else:
-                self.process_event(event)
+                try:
+                    self.process_event(event)
+                except Exception as e:
+                    logger.critical(
+                        "{0} exception raised in {0}".format(e, self.NAME),
+                        exc_info=True,
+                        extra={"event": event},
+                    )
 
     def process_config(self, config: config):
         logger.debug("process_config: %s" % config)
diff --git a/flumine/execution/baseexecution.py b/flumine/execution/baseexecution.py
index 07d9cc5..1fdc56b 100644
--- a/flumine/execution/baseexecution.py
+++ b/flumine/execution/baseexecution.py
@@ -3,6 +3,7 @@ import requests
 from concurrent.futures import ThreadPoolExecutor
 
 from ..order.orderpackage import BaseOrderPackage, OrderPackageType, BaseOrder
+from ..events.events import OrderEvent
 
 logger = logging.getLogger(__name__)
 
@@ -72,7 +73,7 @@ class BaseExecution:
         if package_type == OrderPackageType.PLACE:
             order.responses.placed(instruction_report)
             order.bet_id = instruction_report.bet_id
-            self.flumine.log_control(order)
+            self.flumine.log_control(OrderEvent(order))
         elif package_type == OrderPackageType.CANCEL:
             order.responses.cancelled(instruction_report)
         elif package_type == OrderPackageType.UPDATE:
@@ -80,7 +81,7 @@ class BaseExecution:
         elif package_type == OrderPackageType.REPLACE:
             order.responses.placed(instruction_report)
             order.bet_id = instruction_report.bet_id
-            self.flumine.log_control(order)
+            self.flumine.log_control(OrderEvent(order))
 
     @property
     def handler_queue(self):


Test patch:
diff --git a/tests/test_execution.py b/tests/test_execution.py
index ec8b487..7b08c63 100644
--- a/tests/test_execution.py
+++ b/tests/test_execution.py
@@ -90,7 +90,8 @@ class BaseExecutionTest(unittest.TestCase):
         with self.assertRaises(NotImplementedError):
             self.execution.execute_place(None, None)
 
-    def test__order_logger_place(self):
+    @mock.patch("flumine.execution.baseexecution.OrderEvent")
+    def test__order_logger_place(self, mock_order_event):
         mock_order = mock.Mock()
         mock_instruction_report = mock.Mock()
         self.execution._order_logger(
@@ -98,7 +99,7 @@ class BaseExecutionTest(unittest.TestCase):
         )
         self.assertEqual(mock_order.bet_id, mock_instruction_report.bet_id)
         mock_order.responses.placed.assert_called_with(mock_instruction_report)
-        self.mock_flumine.log_control.assert_called_with(mock_order)
+        self.mock_flumine.log_control.assert_called_with(mock_order_event(mock_order))
 
     def test__order_logger_cancel(self):
         mock_order = mock.Mock()
@@ -116,7 +117,8 @@ class BaseExecutionTest(unittest.TestCase):
         )
         mock_order.responses.updated.assert_called_with(mock_instruction_report)
 
-    def test__order_logger_replace(self):
+    @mock.patch("flumine.execution.baseexecution.OrderEvent")
+    def test__order_logger_replace(self, mock_order_event):
         mock_order = mock.Mock()
         mock_instruction_report = mock.Mock()
         self.execution._order_logger(
@@ -124,7 +126,7 @@ class BaseExecutionTest(unittest.TestCase):
         )
         self.assertEqual(mock_order.bet_id, mock_instruction_report.bet_id)
         mock_order.responses.placed.assert_called_with(mock_instruction_report)
-        self.mock_flumine.log_control.assert_called_with(mock_order)
+        self.mock_flumine.log_control.assert_called_with(mock_order_event(mock_order))
 
     def test_handler_queue(self):
         self.assertEqual(self.execution.handler_queue, self.mock_flumine.handler_queue)
diff --git a/tests/test_loggingcontrols.py b/tests/test_loggingcontrols.py
index c3a9c01..b09683c 100644
--- a/tests/test_loggingcontrols.py
+++ b/tests/test_loggingcontrols.py
@@ -18,6 +18,11 @@ class TestLoggingControl(unittest.TestCase):
         self.logging_control.logging_queue.put(None)
         self.logging_control.run()
 
+    def test_run_error(self):
+        self.logging_control.logging_queue.put(1)
+        self.logging_control.logging_queue.put(None)
+        self.logging_control.run()
+
     @mock.patch("flumine.controls.loggingcontrols.LoggingControl._process_strategy")
     def test_process_event_strategy(self, mock_process_strategy):
         mock_event = mock.Mock()