Repository: digitalfabrik/integreat-cms

Issue:
Development server not starting when GVZ API not reachable
### Describe the Bug
<!-- A clear and concise description of what the bug is. -->
When the [GVZ API](http://gvz.integreat-app.de/api/search/expect_empty_json) is reachable, but does not answer, the development server hangs during start, because there is no timeout defined for the api request [here](https://github.com/Integreat/cms-django/blob/f4f4c698575e975655b1333f630b5f0d6e4e034f/src/gvz_api/apps.py#L27).

### Steps to Reproduce

1. Execute `./dev-tools/run.sh` when GVZ API is reachable but does not answer (tested this morning)
2. Wait

### Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->
The server should start and print a log message that the gvz api is not available

### Actual Behavior
<!-- A clear and concise description of what actually happened. -->
The server does not start

### Additional Information
<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->


Development server not starting when GVZ API not reachable
### Describe the Bug
<!-- A clear and concise description of what the bug is. -->
When the [GVZ API](http://gvz.integreat-app.de/api/search/expect_empty_json) is reachable, but does not answer, the development server hangs during start, because there is no timeout defined for the api request [here](https://github.com/Integreat/cms-django/blob/f4f4c698575e975655b1333f630b5f0d6e4e034f/src/gvz_api/apps.py#L27).

### Steps to Reproduce

1. Execute `./dev-tools/run.sh` when GVZ API is reachable but does not answer (tested this morning)
2. Wait

### Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->
The server should start and print a log message that the gvz api is not available

### Actual Behavior
<!-- A clear and concise description of what actually happened. -->
The server does not start

### Additional Information
<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->




Discussion:

Resolving patch:
diff --git a/src/backend/settings.py b/src/backend/settings.py
--- a/src/backend/settings.py
+++ b/src/backend/settings.py
@@ -197,7 +197,9 @@
     "loggers": {
         "django": {"handlers": ["console"], "level": "WARN", "propagate": True,},
         "api": {"handlers": ["console"], "level": "INFO", "propagate": True,},
+        "backend": {"handlers": ["console"], "level": "INFO", "propagate": True,},
         "cms": {"handlers": ["console"], "level": "INFO", "propagate": True,},
+        "gvz_api": {"handlers": ["console"], "level": "INFO", "propagate": True,},
         "rules": {"handlers": ["console"], "level": "DEBUG", "propagate": True,},
         "auth": {"handlers": ["console", "authlog", "syslog"], "level": "INFO",},
     },
@@ -225,7 +227,7 @@
 COMPRESS_OFFLINE = True
 
 # GVZ (Gemeindeverzeichnis) API URL
-GVZ_API_URL = "http://gvz.integreat-app.de/api/"
+GVZ_API_URL = "https://gvz.integreat-app.de/api/"
 GVZ_API_ENABLED = True
 
 # Allow access to all domains by setting the following variable to TRUE
diff --git a/src/gvz_api/apps.py b/src/gvz_api/apps.py
--- a/src/gvz_api/apps.py
+++ b/src/gvz_api/apps.py
@@ -1,6 +1,7 @@
 """
 Configuration of GVZ API app
 """
+import sys
 import logging
 import json
 import requests
@@ -22,25 +23,25 @@ def ready(self):
         """
         Checking if API is available
         """
-        if settings.GVZ_API_ENABLED:
-            try:
-                response = requests.get(
-                    f"{settings.GVZ_API_URL}/search/expect_empty_json"
-                )
-                json.loads(response.text)
-            except json.decoder.JSONDecodeError:
-                self.api_available = False
-            except requests.exceptions.RequestException:
-                self.api_available = False
+        # Only check availability if current command is "runserver"
+        if sys.argv[1] == "runserver":
+            if settings.GVZ_API_ENABLED:
+                try:
+                    response = requests.get(
+                        f"{settings.GVZ_API_URL}/search/expect_empty_json", timeout=3
+                    )
+                    json.loads(response.text)
+                except (
+                    json.decoder.JSONDecodeError,
+                    requests.exceptions.RequestException,
+                    requests.exceptions.Timeout,
+                ):
+                    logger.info(
+                        "GVZ API is not available. You won't be able to "
+                        "automatically import coordinates and region aliases."
+                    )
+                else:
+                    self.api_available = True
+                    logger.debug("GVZ API is available.")
             else:
-                self.api_available = True
-        else:
-            self.api_available = False
-        if not self.api_available:
-            logger.info(
-                "GVZ API is not available. You won't be able to "
-                "automatically import coordinates and region aliases."
-            )
-        else:
-            self.api_available = True
-            logger.info("GVZ API is available.")
+                logger.debug("GVZ API is not enabled.")


Test patch: