From 0346d6fcfd2ed66b2953ebb61b1906696150f7e1 Mon Sep 17 00:00:00 2001
From: Fabian Schindler <fabian.schindler.strauss@gmail.com>
Date: Wed, 3 Aug 2022 11:47:04 +0200
Subject: [PATCH] Adding `error_queue` Renaming output_queue to success_queue

---
 registrar/config.py       |  7 ++---
 registrar/config.yaml     |  2 ++
 registrar/daemon.py       | 14 +++++-----
 tests/test_config.py      | 10 ++++---
 tests/test_registrar.py   |  4 +--
 tests/testapp/backends.py | 57 ++++++++++++++++++++++++++++-----------
 6 files changed, 63 insertions(+), 31 deletions(-)

diff --git a/registrar/config.py b/registrar/config.py
index cf17e98..f869681 100644
--- a/registrar/config.py
+++ b/registrar/config.py
@@ -164,8 +164,9 @@ class RouteConfig:
 
     path: str
     queue: str
-    default_mode: RouteMode = RouteMode.REGISTER
-    output_queue: Optional[str] = None
+    mode: RouteMode = RouteMode.REGISTER
+    success_queue: Optional[str] = None
+    error_queue: Optional[str] = None
     replace: bool = False
     backends: List[BackendConfig] = field(default_factory=list)
     handlers: HandlersConfig = field(default_factory=HandlersConfig)
@@ -181,7 +182,7 @@ class RouteConfig:
                 BackendConfig(**backend_cfg)
                 for backend_cfg in values.pop("backends")
             ],
-            default_mode=RouteMode(
+            mode=RouteMode(
                 values.pop("default_mode", "REGISTER").upper()
             ),
             **values,
diff --git a/registrar/config.yaml b/registrar/config.yaml
index 363ec17..1ae0281 100644
--- a/registrar/config.yaml
+++ b/registrar/config.yaml
@@ -2,6 +2,8 @@ routes:
   items:
     type: STAC-Item
     queue: register
+    success_queue: seed
+    error_queue: error
     replace: true
     backends:
       - path: registrar.backend.eoxserver.EOxServerItemBackend
diff --git a/registrar/daemon.py b/registrar/daemon.py
index 6cd59ff..c68215b 100644
--- a/registrar/daemon.py
+++ b/registrar/daemon.py
@@ -49,15 +49,17 @@ def run_daemon(config: RegistrarConfig):
 
         try:
             route_cfg = queue_to_route[queue]
-            if route_cfg.default_mode == RouteMode.REGISTER:
+            if route_cfg.mode == RouteMode.REGISTER:
                 register(route_cfg, config.sources, value)
-            elif route_cfg.default_mode == RouteMode.DEREGISTER:
+            elif route_cfg.mode == RouteMode.DEREGISTER:
                 deregister(route_cfg, config.sources, value)
-            elif route_cfg.default_mode == RouteMode.DEREGISTER_IDENTIFIER:
+            elif route_cfg.mode == RouteMode.DEREGISTER_IDENTIFIER:
                 deregister(route_cfg, config.sources, value, use_id=True)
 
-            if route_cfg.output_queue is not None:
-                client.lpush(route_cfg.output_queue, value)
+            if route_cfg.success_queue is not None:
+                client.lpush(route_cfg.success_queue, value)
 
-        except Exception as exc:
+        except Exception as exc:  # pylint: disable=W0703
             logger.exception(exc)
+            if route_cfg.error_queue is not None:
+                client.lpush(route_cfg.error_queue, value)
diff --git a/tests/test_config.py b/tests/test_config.py
index 4052460..c241fc2 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -19,7 +19,8 @@ def config_simple():
               items:
                 path: registrar.route.stac.ItemRoute
                 queue: register
-                output_queue: next_queue
+                success_queue: next_queue
+                error_queue: error_queue
                 backends:
                   - path: registrar.backend.eoxserver.EOxServerItemBackend
                     kwargs:
@@ -56,9 +57,10 @@ def test_config(config_simple):
         {
             "items": RouteConfig(
                 "registrar.route.stac.ItemRoute",
-                "register",
-                default_mode=RouteMode.REGISTER,
-                output_queue="next_queue",
+                queue="register",
+                mode=RouteMode.REGISTER,
+                success_queue="next_queue",
+                error_queue="error_queue",
                 backends=[
                     BackendConfig(
                         "registrar.backend.eoxserver.EOxServerItemBackend",
diff --git a/tests/test_registrar.py b/tests/test_registrar.py
index d9c68ee..78af91f 100644
--- a/tests/test_registrar.py
+++ b/tests/test_registrar.py
@@ -53,7 +53,7 @@ def test_register_item(mocker):
         {
             "items": RouteConfig(
                 "registrar.route.stac.ItemRoute",
-                "register",
+                queue="register",
                 replace=True,
                 backends=[
                     BackendConfig(
@@ -94,7 +94,7 @@ def test_handlers(mocker):
         {
             "items": RouteConfig(
                 "registrar.route.stac.ItemRoute",
-                "register",
+                queue="register",
                 replace=True,
                 backends=[
                     BackendConfig(
diff --git a/tests/testapp/backends.py b/tests/testapp/backends.py
index 082e08d..c59579c 100644
--- a/tests/testapp/backends.py
+++ b/tests/testapp/backends.py
@@ -6,33 +6,58 @@ from registrar.source import Source
 
 
 class MyPathBackend(Backend[str]):
+    """ Testing backend
+    """
     def __init__(self, exists: False):
-        self.exists = exists
+        self.exists_ = exists
 
-    def exists(self, source: Optional[Source], path: str) -> bool:
-        return self.exists
+    def exists(self, source: Optional[Source], item: str) -> bool:
+        return self.exists_
 
-    def register(self, source: Optional[Source], path: str, replace: bool):
+    def register(self, source: Optional[Source], item: str, replace: bool):
         ...
 
-    def deregister(self, source: Optional[Source], path: str) -> Optional[str]:
-        return path
+    def deregister(self, source: Optional[Source], item: str):
+        ...
+
+    def deregister_identifier(self, identifier: str):
+        ...
 
-    def deregister_identifier(self, identifier: str) -> Optional[str]:
-        return identifier
 
 class MyItemBackend(Backend[Item]):
+    """ Testing backend
+    """
     def __init__(self, exists: False):
-        self._exists = exists
+        self.exists_ = exists
 
-    def exists(self, source: Optional[Source], item: "Item") -> bool:
-        return self._exists
+    def exists(self, source: Optional[Source], item: Item) -> bool:
+        return self.exists_
+
+    def register(self, source: Optional[Source], item: Item, replace: bool):
+        ...
 
-    def register(self, source: Optional[Source], item: "Item", replace: bool):
+    def deregister(self, source: Optional[Source], item: Item):
         ...
 
-    def deregister(self, source: Optional[Source], path: str) -> Optional[str]:
-        return path
+    def deregister_identifier(self, identifier: str):
+        ...
+
+
+
 
-    def deregister_identifier(self, identifier: str) -> Optional[str]:
-        return identifier
+
+
+class CWLBackend(Backend[dict]):
+    """ Testing backend
+    """
+    def exists(self, source: Optional[Source], item: dict) -> bool:
+        return self.exists_
+
+    def register(self, source: Optional[Source], item: dict, replace: bool):
+        ...
+
+    def deregister(self, source: Optional[Source], item: dict):
+        ...
+
+    def deregister_identifier(self, identifier: str):
+        ...
-- 
GitLab