You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2020/09/10 09:34:23 UTC

[incubator-ponymail-foal] branch master updated: Fail gracefully if DB is down, don't tank the entire program

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new e8481a3  Fail gracefully if DB is down, don't tank the entire program
e8481a3 is described below

commit e8481a39b11ade321dc27a9628f58d335e917c89
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Thu Sep 10 11:34:09 2020 +0200

    Fail gracefully if DB is down, don't tank the entire program
---
 server/plugins/background.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/server/plugins/background.py b/server/plugins/background.py
index 1c1b91f..69095bc 100644
--- a/server/plugins/background.py
+++ b/server/plugins/background.py
@@ -10,6 +10,7 @@ from elasticsearch_dsl import Search
 
 import plugins.configuration
 import plugins.server
+import plugins.database
 
 PYPONY_RE_PREFIX = re.compile(r"^([a-zA-Z]+:\s*)+")
 
@@ -56,6 +57,7 @@ async def get_lists(database: plugins.configuration.DBConfig) -> dict:
     )
     s.aggs.bucket("per_list", "terms", field="list_raw")
 
+
     res = await client.search(
         index=database.db_prefix + "-mbox", body=s.to_dict(), size=0
     )
@@ -198,7 +200,13 @@ async def run_tasks(server: plugins.server.BaseServer):
     """
     while True:
         async with ProgTimer("Gathering list of archived mailing lists"):
-            server.data.lists = await get_lists(server.config.database)
+            try:
+                server.data.lists = await get_lists(server.config.database)
+            except plugins.database.DBError:
+                print("Could not fetch lists - database down or not connected?!")
         async with ProgTimer("Gathering bi-weekly activity stats"):
-            server.data.activity = await get_public_activity(server.config.database)
+            try:
+                server.data.activity = await get_public_activity(server.config.database)
+            except plugins.database.DBError:
+                print("Could not fetch activity data - database down or not connected?!")
         await asyncio.sleep(server.config.tasks.refresh_rate)