From 2b1a92b311a1f99df1670b73d14c6763c6207ead Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Wed, 16 Oct 2024 16:47:05 +0700 Subject: [PATCH 01/16] feat: add db_heartbeat --- health_check/contrib/db_heartbeat/__init__.py | 4 ++++ health_check/contrib/db_heartbeat/apps.py | 10 +++++++++ health_check/contrib/db_heartbeat/backends.py | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 health_check/contrib/db_heartbeat/__init__.py create mode 100644 health_check/contrib/db_heartbeat/apps.py create mode 100644 health_check/contrib/db_heartbeat/backends.py diff --git a/health_check/contrib/db_heartbeat/__init__.py b/health_check/contrib/db_heartbeat/__init__.py new file mode 100644 index 00000000..7aad707f --- /dev/null +++ b/health_check/contrib/db_heartbeat/__init__.py @@ -0,0 +1,4 @@ +import django + +if django.VERSION < (3, 2): + default_app_config = "health_check.contrib.db_heartbeat.apps.HealthCheckConfig" \ No newline at end of file diff --git a/health_check/contrib/db_heartbeat/apps.py b/health_check/contrib/db_heartbeat/apps.py new file mode 100644 index 00000000..896c2472 --- /dev/null +++ b/health_check/contrib/db_heartbeat/apps.py @@ -0,0 +1,10 @@ +from django.apps import AppConfig +from health_check.plugins import plugin_dir + + +class HealthCheckConfig(AppConfig): + name = 'health_check.contrib.db_heartbeat' + + def ready(self): + from .backends import DatabaseHeartBeatCheck + plugin_dir.register(DatabaseHeartBeatCheck) diff --git a/health_check/contrib/db_heartbeat/backends.py b/health_check/contrib/db_heartbeat/backends.py new file mode 100644 index 00000000..ca9bb318 --- /dev/null +++ b/health_check/contrib/db_heartbeat/backends.py @@ -0,0 +1,21 @@ +from health_check.backends import BaseHealthCheckBackend +from health_check.exceptions import ServiceUnavailable, ServiceReturnedUnexpectedResult +from django.db import connection + + +class DatabaseHeartBeatCheck(BaseHealthCheckBackend): + """ + Health check that runs a simple SELECT 1; query to test if the database connection is alive. + """ + + def check_status(self): + try: + result = None + with connection.cursor() as cursor: + cursor.execute("SELECT 1;") + result = cursor.fetchone() + + if result != (1,): + raise ServiceReturnedUnexpectedResult("Health Check query did not return the expected result.") + except Exception as e: + raise ServiceUnavailable(f"Database health check failed: {e}") From 54a588d2b63b877f4ca9a9764d9e6e7efc4fb7c9 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Mon, 21 Oct 2024 08:51:11 +0700 Subject: [PATCH 02/16] feat: add tests --- health_check/contrib/db_heartbeat/__init__.py | 2 +- health_check/contrib/db_heartbeat/apps.py | 3 ++- health_check/contrib/db_heartbeat/backends.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/health_check/contrib/db_heartbeat/__init__.py b/health_check/contrib/db_heartbeat/__init__.py index 7aad707f..3a3efc65 100644 --- a/health_check/contrib/db_heartbeat/__init__.py +++ b/health_check/contrib/db_heartbeat/__init__.py @@ -1,4 +1,4 @@ import django if django.VERSION < (3, 2): - default_app_config = "health_check.contrib.db_heartbeat.apps.HealthCheckConfig" \ No newline at end of file + default_app_config = "health_check.contrib.db_heartbeat.apps.HealthCheckConfig" diff --git a/health_check/contrib/db_heartbeat/apps.py b/health_check/contrib/db_heartbeat/apps.py index 896c2472..3b5edec6 100644 --- a/health_check/contrib/db_heartbeat/apps.py +++ b/health_check/contrib/db_heartbeat/apps.py @@ -3,8 +3,9 @@ class HealthCheckConfig(AppConfig): - name = 'health_check.contrib.db_heartbeat' + name = "health_check.contrib.db_heartbeat" def ready(self): from .backends import DatabaseHeartBeatCheck + plugin_dir.register(DatabaseHeartBeatCheck) diff --git a/health_check/contrib/db_heartbeat/backends.py b/health_check/contrib/db_heartbeat/backends.py index ca9bb318..e0473b9d 100644 --- a/health_check/contrib/db_heartbeat/backends.py +++ b/health_check/contrib/db_heartbeat/backends.py @@ -16,6 +16,8 @@ def check_status(self): result = cursor.fetchone() if result != (1,): - raise ServiceReturnedUnexpectedResult("Health Check query did not return the expected result.") + raise ServiceReturnedUnexpectedResult( + "Health Check query did not return the expected result." + ) except Exception as e: raise ServiceUnavailable(f"Database health check failed: {e}") From 786b6bbe8ae4c98cbe45e2df94ecb323d44da057 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Mon, 21 Oct 2024 08:54:11 +0700 Subject: [PATCH 03/16] feat: add ignore .DS_Store --- .gitignore | 3 +++ health_check/.DS_Store | Bin 0 -> 6148 bytes health_check/contrib/.DS_Store | Bin 0 -> 6148 bytes health_check/contrib/db_heartbeat/backends.py | 4 +--- 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 health_check/.DS_Store create mode 100644 health_check/contrib/.DS_Store diff --git a/.gitignore b/.gitignore index 427607d3..84debe81 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,6 @@ ENV/ .envrc .direnv + +# mac +.DS_Store \ No newline at end of file diff --git a/health_check/.DS_Store b/health_check/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3637fa1274d7fdd0be5735967fe4ebaedf20f050 GIT binary patch literal 6148 zcmeHK!AiqG5Z!I7-BN@c6nb3nS}dYBF;KHK%5<%70-_~aBd0T;_uO7r_WCD_ zuAKLeT(FN%7mJqI+dnwF96cv5sd_b3a@;-2j)B$qwz9||28aP-fEXYKHW{$DhiGpG z$R`Gffq%~co(~cf(X&_@)JF#lx&;7iz_b>yv6sLaY0H54l-m}An{t?! zHqWzI8Z_mM+vbDYCoh{9uAdI;OP$WRXOKo>fEZY3pl)0T@Ba(i}bvUlsZ*TcJ3f{($PT^muN$tXR$PhtKhsY2c#bX MO$ZIdzz;C+3B#sFNB{r; literal 0 HcmV?d00001 diff --git a/health_check/contrib/.DS_Store b/health_check/contrib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8122eb908c78a20c2b580dc8e22e062f27716ccd GIT binary patch literal 6148 zcmeHK!AiqG5S?wSO{qc;3OxqA7Ob`u#7l_v2aM=JB_<@$V9b^#C5KYTS%1hc@q3)v z-4>!f3(5@4zS*6b&F+Kj?f`&rm(dwO4*)DwLP5q3q2Zmbh6xsks5nOq0W6?^5Usx< zwDtptaK%2%YU>Z62+MpPrZU8sk8qwQc`+P*ibk`wx8JtfR@Zv+X0r5(pjhT^uy~-} zt(0lFv4ij~iA%qCbS1MQNV0gL5|Sv!kjMKZi)87_WftWs*V7KGV|Dyqf3+HqMgx01 znXCu)>f(He_Gq$RcdX-+)5{zGC4J50o2FUNK1dEVY}@y(#RfCL3@`)C05hN&Fn5O4 zWkQ$%W`G&^#sHlUHY%ZGu+pfG4s28jfY`!eC1_JEK{>WT$6%!qJt#t_BI;CON(`aX zaojd>j=@T!P6uI%4`IH%DPDy7I?ivaa1f40ZkYjQpw2*3cYAdIU*j*cv&gTfaE}>a z2L2fXqBZrVE^f-)tv|L$cdd>3j7mar6&WaK*B$}bp>w3KoZ4@bjd6~_N+Zoe<0>7I O9|DRHZkT~zVBib;%0}G) literal 0 HcmV?d00001 diff --git a/health_check/contrib/db_heartbeat/backends.py b/health_check/contrib/db_heartbeat/backends.py index e0473b9d..e7fde43e 100644 --- a/health_check/contrib/db_heartbeat/backends.py +++ b/health_check/contrib/db_heartbeat/backends.py @@ -4,9 +4,7 @@ class DatabaseHeartBeatCheck(BaseHealthCheckBackend): - """ - Health check that runs a simple SELECT 1; query to test if the database connection is alive. - """ + """ Health check that runs a simple SELECT 1; query to test if the database connection is alive. """ def check_status(self): try: From 632564608abebc801498c16f981e2717df9867f0 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Mon, 21 Oct 2024 09:07:40 +0700 Subject: [PATCH 04/16] fix: linting errors --- health_check/contrib/db_heartbeat/backends.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/health_check/contrib/db_heartbeat/backends.py b/health_check/contrib/db_heartbeat/backends.py index e7fde43e..10976cc4 100644 --- a/health_check/contrib/db_heartbeat/backends.py +++ b/health_check/contrib/db_heartbeat/backends.py @@ -4,7 +4,7 @@ class DatabaseHeartBeatCheck(BaseHealthCheckBackend): - """ Health check that runs a simple SELECT 1; query to test if the database connection is alive. """ + """Health check that runs a simple SELECT 1; query to test if the database connection is alive.""" def check_status(self): try: From 88f058790f4f3ae581cde70dd31798f36d8f7bc5 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Mon, 21 Oct 2024 11:06:11 +0700 Subject: [PATCH 05/16] fix: linting errors --- health_check/contrib/db_heartbeat/apps.py | 1 + 1 file changed, 1 insertion(+) diff --git a/health_check/contrib/db_heartbeat/apps.py b/health_check/contrib/db_heartbeat/apps.py index 3b5edec6..d05fc806 100644 --- a/health_check/contrib/db_heartbeat/apps.py +++ b/health_check/contrib/db_heartbeat/apps.py @@ -1,4 +1,5 @@ from django.apps import AppConfig + from health_check.plugins import plugin_dir From 57066fb34bf30b2af50e8a582696c082588b2363 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Mon, 21 Oct 2024 11:08:06 +0700 Subject: [PATCH 06/16] fix: linting errors --- health_check/contrib/db_heartbeat/backends.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/health_check/contrib/db_heartbeat/backends.py b/health_check/contrib/db_heartbeat/backends.py index 10976cc4..5cc794fa 100644 --- a/health_check/contrib/db_heartbeat/backends.py +++ b/health_check/contrib/db_heartbeat/backends.py @@ -1,7 +1,8 @@ -from health_check.backends import BaseHealthCheckBackend -from health_check.exceptions import ServiceUnavailable, ServiceReturnedUnexpectedResult from django.db import connection +from health_check.backends import BaseHealthCheckBackend +from health_check.exceptions import ServiceReturnedUnexpectedResult, ServiceUnavailable + class DatabaseHeartBeatCheck(BaseHealthCheckBackend): """Health check that runs a simple SELECT 1; query to test if the database connection is alive.""" From af10d618f00bdc22ea41a83c6099f72a5691ebfd Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Mon, 21 Oct 2024 11:13:30 +0700 Subject: [PATCH 07/16] feat: remove .ds_store --- health_check/.DS_Store | Bin 6148 -> 0 bytes health_check/contrib/.DS_Store | Bin 6148 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 health_check/.DS_Store delete mode 100644 health_check/contrib/.DS_Store diff --git a/health_check/.DS_Store b/health_check/.DS_Store deleted file mode 100644 index 3637fa1274d7fdd0be5735967fe4ebaedf20f050..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!AiqG5Z!I7-BN@c6nb3nS}dYBF;KHK%5<%70-_~aBd0T;_uO7r_WCD_ zuAKLeT(FN%7mJqI+dnwF96cv5sd_b3a@;-2j)B$qwz9||28aP-fEXYKHW{$DhiGpG z$R`Gffq%~co(~cf(X&_@)JF#lx&;7iz_b>yv6sLaY0H54l-m}An{t?! zHqWzI8Z_mM+vbDYCoh{9uAdI;OP$WRXOKo>fEZY3pl)0T@Ba(i}bvUlsZ*TcJ3f{($PT^muN$tXR$PhtKhsY2c#bX MO$ZIdzz;C+3B#sFNB{r; diff --git a/health_check/contrib/.DS_Store b/health_check/contrib/.DS_Store deleted file mode 100644 index 8122eb908c78a20c2b580dc8e22e062f27716ccd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!AiqG5S?wSO{qc;3OxqA7Ob`u#7l_v2aM=JB_<@$V9b^#C5KYTS%1hc@q3)v z-4>!f3(5@4zS*6b&F+Kj?f`&rm(dwO4*)DwLP5q3q2Zmbh6xsks5nOq0W6?^5Usx< zwDtptaK%2%YU>Z62+MpPrZU8sk8qwQc`+P*ibk`wx8JtfR@Zv+X0r5(pjhT^uy~-} zt(0lFv4ij~iA%qCbS1MQNV0gL5|Sv!kjMKZi)87_WftWs*V7KGV|Dyqf3+HqMgx01 znXCu)>f(He_Gq$RcdX-+)5{zGC4J50o2FUNK1dEVY}@y(#RfCL3@`)C05hN&Fn5O4 zWkQ$%W`G&^#sHlUHY%ZGu+pfG4s28jfY`!eC1_JEK{>WT$6%!qJt#t_BI;CON(`aX zaojd>j=@T!P6uI%4`IH%DPDy7I?ivaa1f40ZkYjQpw2*3cYAdIU*j*cv&gTfaE}>a z2L2fXqBZrVE^f-)tv|L$cdd>3j7mar6&WaK*B$}bp>w3KoZ4@bjd6~_N+Zoe<0>7I O9|DRHZkT~zVBib;%0}G) From 339aa06a43502ac67fc190e0ba4cc620905831f7 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Mon, 21 Oct 2024 15:06:59 +0700 Subject: [PATCH 08/16] feat: add tests --- tests/test_db_heartbeat.py | 23 +++++++++++++++++++++++ tests/testapp/settings.py | 1 + 2 files changed, 24 insertions(+) create mode 100644 tests/test_db_heartbeat.py diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py new file mode 100644 index 00000000..bc6d54b5 --- /dev/null +++ b/tests/test_db_heartbeat.py @@ -0,0 +1,23 @@ +import unittest + +from health_check.contrib.db_heartbeat import DatabaseHeartBeatCheck +from health_check.exceptions import ServiceUnavailable + + +class TestDatabaseHeartBeatCheck(unittest.TestCase): + + def test_check_status_success(self): + health_check = DatabaseHeartBeatCheck() + try: + health_check.check_status() # Should pass without exceptions + except Exception as e: + self.fail(f"check_status() raised an exception unexpectedly: {e}") + + def test_check_status_unexpected_result(self): + health_check = DatabaseHeartBeatCheck() + with self.assertRaises(ServiceUnavailable): + health_check.check_status() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/testapp/settings.py b/tests/testapp/settings.py index 620e7190..46c16aad 100644 --- a/tests/testapp/settings.py +++ b/tests/testapp/settings.py @@ -30,6 +30,7 @@ "health_check.contrib.migrations", "health_check.contrib.celery_ping", "health_check.contrib.s3boto_storage", + "health_check.contrib.db_heartbeat", "tests", ) From b10ab34b409eb4a2a7ca2ec4b6e3ff216208268b Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Tue, 22 Oct 2024 08:01:22 +0700 Subject: [PATCH 09/16] fix: test linting --- tests/test_db_heartbeat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py index bc6d54b5..c49b8fe2 100644 --- a/tests/test_db_heartbeat.py +++ b/tests/test_db_heartbeat.py @@ -5,7 +5,6 @@ class TestDatabaseHeartBeatCheck(unittest.TestCase): - def test_check_status_success(self): health_check = DatabaseHeartBeatCheck() try: From 536c849c90a2a24ead39b1beff75ab20565829d2 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Tue, 22 Oct 2024 13:02:49 +0700 Subject: [PATCH 10/16] feat: fix incorrect imports --- tests/test_db_heartbeat.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py index c49b8fe2..6cc39df1 100644 --- a/tests/test_db_heartbeat.py +++ b/tests/test_db_heartbeat.py @@ -1,6 +1,6 @@ import unittest -from health_check.contrib.db_heartbeat import DatabaseHeartBeatCheck +from health_check.contrib.db_heartbeat.backends import DatabaseHeartBeatCheck from health_check.exceptions import ServiceUnavailable @@ -16,7 +16,3 @@ def test_check_status_unexpected_result(self): health_check = DatabaseHeartBeatCheck() with self.assertRaises(ServiceUnavailable): health_check.check_status() - - -if __name__ == "__main__": - unittest.main() From 17db25328e616c46dafe5af6f9c33c72a6991f86 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Sun, 27 Oct 2024 16:48:13 +0700 Subject: [PATCH 11/16] feat: add test mocking --- tests/test_db_heartbeat.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py index 6cc39df1..70008fee 100644 --- a/tests/test_db_heartbeat.py +++ b/tests/test_db_heartbeat.py @@ -1,18 +1,37 @@ import unittest - +from unittest.mock import patch, MagicMock from health_check.contrib.db_heartbeat.backends import DatabaseHeartBeatCheck -from health_check.exceptions import ServiceUnavailable +from health_check.exceptions import ServiceUnavailable, ServiceReturnedUnexpectedResult class TestDatabaseHeartBeatCheck(unittest.TestCase): - def test_check_status_success(self): + + @patch("health_check.contrib.db_heartbeat.backends.connection") + def test_check_status_success(self, mock_connection): + mock_cursor = MagicMock() + mock_cursor.fetchone.return_value = (1,) + mock_connection.cursor.return_value.__enter__.return_value = mock_cursor + health_check = DatabaseHeartBeatCheck() try: - health_check.check_status() # Should pass without exceptions + health_check.check_status() except Exception as e: self.fail(f"check_status() raised an exception unexpectedly: {e}") - def test_check_status_unexpected_result(self): + @patch("health_check.contrib.db_heartbeat.backends.connection") + def test_check_status_unexpected_result(self, mock_connection): + mock_cursor = MagicMock() + mock_cursor.fetchone.return_value = (0,) + mock_connection.cursor.return_value.__enter__.return_value = mock_cursor + + health_check = DatabaseHeartBeatCheck() + with self.assertRaises(ServiceReturnedUnexpectedResult): + health_check.check_status() + + @patch("health_check.contrib.db_heartbeat.backends.connection") + def test_check_status_service_unavailable(self, mock_connection): + mock_connection.cursor.side_effect = Exception("Database error") + health_check = DatabaseHeartBeatCheck() with self.assertRaises(ServiceUnavailable): health_check.check_status() From d0563c40aaf1d4d2af29750f1dc3aaa159ff0ea1 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Sun, 27 Oct 2024 16:50:15 +0700 Subject: [PATCH 12/16] fix: linting --- tests/test_db_heartbeat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py index 70008fee..0b1ac460 100644 --- a/tests/test_db_heartbeat.py +++ b/tests/test_db_heartbeat.py @@ -1,7 +1,8 @@ import unittest -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock, patch + from health_check.contrib.db_heartbeat.backends import DatabaseHeartBeatCheck -from health_check.exceptions import ServiceUnavailable, ServiceReturnedUnexpectedResult +from health_check.exceptions import ServiceReturnedUnexpectedResult, ServiceUnavailable class TestDatabaseHeartBeatCheck(unittest.TestCase): From 80addb03ec2bbec62721aa2ffc0b29435706b083 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Sun, 27 Oct 2024 16:51:47 +0700 Subject: [PATCH 13/16] fix: linting --- tests/test_db_heartbeat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py index 0b1ac460..cc65b513 100644 --- a/tests/test_db_heartbeat.py +++ b/tests/test_db_heartbeat.py @@ -6,7 +6,6 @@ class TestDatabaseHeartBeatCheck(unittest.TestCase): - @patch("health_check.contrib.db_heartbeat.backends.connection") def test_check_status_success(self, mock_connection): mock_cursor = MagicMock() From f6897c5d94ce9d3b2b05f87ea5bf533855fac9cb Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Sun, 27 Oct 2024 16:59:25 +0700 Subject: [PATCH 14/16] fix: tests --- health_check/contrib/db_heartbeat/backends.py | 4 ++-- tests/test_db_heartbeat.py | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/health_check/contrib/db_heartbeat/backends.py b/health_check/contrib/db_heartbeat/backends.py index 5cc794fa..8c6ba30a 100644 --- a/health_check/contrib/db_heartbeat/backends.py +++ b/health_check/contrib/db_heartbeat/backends.py @@ -1,7 +1,7 @@ from django.db import connection from health_check.backends import BaseHealthCheckBackend -from health_check.exceptions import ServiceReturnedUnexpectedResult, ServiceUnavailable +from health_check.exceptions import ServiceUnavailable class DatabaseHeartBeatCheck(BaseHealthCheckBackend): @@ -15,7 +15,7 @@ def check_status(self): result = cursor.fetchone() if result != (1,): - raise ServiceReturnedUnexpectedResult( + raise ServiceUnavailable( "Health Check query did not return the expected result." ) except Exception as e: diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py index cc65b513..b1f5b24f 100644 --- a/tests/test_db_heartbeat.py +++ b/tests/test_db_heartbeat.py @@ -18,16 +18,6 @@ def test_check_status_success(self, mock_connection): except Exception as e: self.fail(f"check_status() raised an exception unexpectedly: {e}") - @patch("health_check.contrib.db_heartbeat.backends.connection") - def test_check_status_unexpected_result(self, mock_connection): - mock_cursor = MagicMock() - mock_cursor.fetchone.return_value = (0,) - mock_connection.cursor.return_value.__enter__.return_value = mock_cursor - - health_check = DatabaseHeartBeatCheck() - with self.assertRaises(ServiceReturnedUnexpectedResult): - health_check.check_status() - @patch("health_check.contrib.db_heartbeat.backends.connection") def test_check_status_service_unavailable(self, mock_connection): mock_connection.cursor.side_effect = Exception("Database error") From 7f380f8415259141f0e3f067bef0a1e569b76814 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Sun, 27 Oct 2024 17:00:48 +0700 Subject: [PATCH 15/16] fix: linting --- tests/test_db_heartbeat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_db_heartbeat.py b/tests/test_db_heartbeat.py index b1f5b24f..abf5e7ca 100644 --- a/tests/test_db_heartbeat.py +++ b/tests/test_db_heartbeat.py @@ -2,7 +2,7 @@ from unittest.mock import MagicMock, patch from health_check.contrib.db_heartbeat.backends import DatabaseHeartBeatCheck -from health_check.exceptions import ServiceReturnedUnexpectedResult, ServiceUnavailable +from health_check.exceptions import ServiceUnavailable class TestDatabaseHeartBeatCheck(unittest.TestCase): From dd1fffe99c6fe4b383283bf73b06e050971e46d1 Mon Sep 17 00:00:00 2001 From: Pan Teparak Date: Mon, 28 Oct 2024 13:16:35 +0700 Subject: [PATCH 16/16] feat: update docs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 833fd270..b408d952 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ The following health checks are bundled with this project: - Celery ping - RabbitMQ - Migrations +- Database Heartbeat (Lightweight version of `health_check.db`) Writing your own custom health checks is also very quick and easy. @@ -74,6 +75,7 @@ Add the `health_check` applications to your `INSTALLED_APPS`: 'health_check.contrib.s3boto3_storage', # requires boto3 and S3BotoStorage backend 'health_check.contrib.rabbitmq', # requires RabbitMQ broker 'health_check.contrib.redis', # requires Redis broker + 'health_check.contrib.db_heartbeat', ] ```