From b0ade94e157f0614bfb69a9428ffb800503f979e Mon Sep 17 00:00:00 2001 From: Steve Jalim Date: Fri, 2 Oct 2020 14:45:50 +0100 Subject: [PATCH 1/2] Support a configurable timeoutfor the API chooser proxy The current default behaviour of 5 seconds is retained, but can be overridden via settings.WAGTAILTRANSFER_CHOOSER_API_PROXY_TIMEOUT --- wagtail_transfer/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wagtail_transfer/views.py b/wagtail_transfer/views.py index 19e4d97..ca2b33d 100644 --- a/wagtail_transfer/views.py +++ b/wagtail_transfer/views.py @@ -168,6 +168,8 @@ class PageChooserAPIViewSet(PagesAdminAPIViewSet): def chooser_api_proxy(request, source_name, path): source_config = getattr(settings, 'WAGTAILTRANSFER_SOURCES', {}).get(source_name) + api_proxy_timeout_seconds = getattr(settings, 'WAGTAILTRANSFER_CHOOSER_API_PROXY_TIMEOUT', 5) + if source_config is None: raise Http404("Source does not exist") @@ -179,7 +181,7 @@ def chooser_api_proxy(request, source_name, path): response = requests.get(f"{base_url}{path}?{request.GET.urlencode()}", headers={ 'Accept': request.META['HTTP_ACCEPT'], - }, timeout=5) + }, timeout=api_proxy_timeout_seconds) return HttpResponse(response.content, status=response.status_code) From 1ad5253000da767fb3918e60958e87ea337a6c5d Mon Sep 17 00:00:00 2001 From: Steve Jalim Date: Mon, 12 Oct 2020 14:11:51 +0100 Subject: [PATCH 2/2] Include mention of new WAGTAILTRANSFER_CHOOSER_API_PROXY_TIMEOUT setting in README and main docs --- README.md | 3 +++ docs/settings.md | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 100b6f4..d9e6ac3 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,9 @@ The following settings are additionally recognised: Note that these settings do not accept models that are defined as subclasses through [multi-table inheritance](https://docs.djangoproject.com/en/stable/topics/db/models/#multi-table-inheritance) - in particular, they cannot be used to define behaviour that only applies to specific subclasses of Page. +* `WAGTAILTRANSFER_CHOOSER_API_PROXY_TIMEOUT = 5` + + By default, each API call made to browse the page tree on the source server has a timeout limit of 5 seconds. If you find this threshold is too low, you can increase it. This may be of particular use if you are running two local runservers to test or extend Wagtail Transfer. ## Management commands diff --git a/docs/settings.md b/docs/settings.md index fe9940b..fabe13e 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -87,6 +87,12 @@ that object will end up with unresolved references, to be handled by the same se Note that these settings do not accept models that are defined as subclasses through multi-table inheritance - in particular, they cannot be used to define behaviour that only applies to specific subclasses of Page. +```python +WAGTAILTRANSFER_CHOOSER_API_PROXY_TIMEOUT = 5 +``` + + By default, each API call made to browse the page tree on the source server has a timeout limit of 5 seconds. If you find this threshold is too low, you can increase it. This may be of particular use if you are running two local runservers to test or extend Wagtail Transfer. + ## Hooks ### `register_field_adapters`