Skip to content

Commit 6ed8f0b

Browse files
authored
Increase UWSGI timeouts; Extract URLs from markdown links in learn_more (#649)
1 parent c66180e commit 6ed8f0b

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

deployment/ckan/setup/start_ckan.sh.override

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ UWSGI_OPTS="--plugins http,python \
6060
--master --enable-threads \
6161
--lazy-apps \
6262
-p 2 -L -b 32768 --vacuum \
63-
--harakiri $UWSGI_HARAKIRI"
63+
--http-keepalive --http-timeout ${UWSGI_HTTP_TIMEOUT:-3600} \
64+
--socket-timeout ${UWSGI_SOCKET_TIMEOUT:-3600} \
65+
--disable-write-exception \
66+
--harakiri ${UWSGI_HARAKIRI:-1800}"
6467

6568
echo "From GitHub Actions: $GITHUB_ACTIONS"
6669
# Check if we are running in GitHub Actions

deployment/helm-templates/values.yaml.dev.template

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ ckan:
55
replicaCount: 2
66
envVarsSecretName: ckan-cloud-centeralized-sql
77
env:
8-
UWSGI_HARAKIRI: "600"
8+
UWSGI_HARAKIRI: "1800"
9+
UWSGI_HTTP_TIMEOUT: "3600"
10+
UWSGI_SOCKET_TIMEOUT: "3600"
911
CKANEXT__DCAT__ENABLE_CONTENT_NEGOTIATION: "True"
1012
CKANEXT__REPO__SRCPATH: /srv/app/src
1113
CKAN_INI: /srv/app/production.ini

migration/tasks/migration_task.py

+35-7
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def iso_language_code(value):
202202
return value
203203

204204

205-
def url_validator(value):
205+
def url_validator(key, value):
206206
"""
207207
Check that the value is a valid URL. Must start with "http://" or "https://".
208208
"ftp://" is not currently supported.
@@ -217,17 +217,40 @@ def url_validator(value):
217217
return value
218218

219219
if isinstance(value, str):
220+
# Attempt to handle markdown links
221+
match = re.match(r"\[.*?\]\((https?://.*?)\)", value)
222+
223+
if match:
224+
log.info(f"{key} - Markdown link found: {value}")
225+
226+
extracted_url = match.group(1)
227+
228+
log.info(f"{key} - Attempting to extract URL: {extracted_url}")
229+
230+
valid_markdown_url = url_validator(key, extracted_url)
231+
232+
if valid_markdown_url:
233+
log.info(f"{key} - URL successfully extracted: {valid_markdown_url}")
234+
235+
return valid_markdown_url
236+
else:
237+
log.error(f"{key} - Failed to extract URL from markdown link: {extracted_url}")
238+
239+
return ""
240+
220241
if not value.startswith("http://") and not value.startswith("https://"):
221-
error_message = 'Value must start with "http://" or "https://"'
242+
error_message = f'{key} - Value must start with "http://" or "https://"'
222243
else:
223-
error_message = "URL is not a string"
244+
error_message = (
245+
f"{key} - Must be a string\nValue: {value}\nValue type: {type(value)}"
246+
)
224247

225248
if error_message:
226249
log.error(error_message)
227250

228251
return ""
229-
else:
230-
return value
252+
253+
return value
231254

232255

233256
def normalize_value(value):
@@ -506,7 +529,7 @@ def migrate_dataset(data_dict):
506529
dataset_value = dataset.get(key)
507530

508531
if (
509-
not all(v in ["", None] for v in [dataset_value, value])
532+
not all(v in ["", [], None] for v in [dataset_value, value])
510533
and dataset_value != value
511534
and key
512535
not in [
@@ -1063,7 +1086,12 @@ def get_value(key, default="", data_object=None):
10631086
language = iso_language_code(language)
10641087

10651088
citation = get_value("citation")
1089+
10661090
learn_more_link = get_value("learn_more") or get_value("learn_more_link")
1091+
1092+
if learn_more_link:
1093+
learn_more_link = url_validator("learn_more", learn_more_link)
1094+
10671095
function = get_value("functions")
10681096

10691097
if function in [None, ""]:
@@ -1075,7 +1103,7 @@ def get_value(key, default="", data_object=None):
10751103
data_download_link = get_value("data_download_link")
10761104

10771105
if data_download_link:
1078-
data_download_link = url_validator(data_download_link)
1106+
data_download_link = url_validator("data_download_link", data_download_link)
10791107

10801108
extras = dataset.get("extras", [])
10811109

0 commit comments

Comments
 (0)