about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-10 13:19:42 +0000
committerPjotr <wrk@bosa.lan>2026-11-10 13:19:42 +0000
commitd5164d9f94aee148fe76d91b1956cf5ef97b3e69 (patch)
tree444905ddb444b7d879e425024130bf2b86186218 /src
parentde4f3601732e47f54b7e1a6423eb98a86ce55efb (diff)
downloadgenenetwork4-d5164d9f94aee148fe76d91b1956cf5ef97b3e69.tar.gz
genes: give the Wikidata call 30 s, not 20
Two SPARQL queries in a row, and Wikidata's query service measured 9 s
for one of them during the deploy -- so the first call for a symbol timed
out at 20 s and answered 502 while the service was merely slow. Only the
first call pays it; the answer is cached for a week. The refusal now says
how long it waited.
Diffstat (limited to 'src')
-rw-r--r--src/wikidata.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/wikidata.rs b/src/wikidata.rs
index 2a69ddb..f5f75a2 100644
--- a/src/wikidata.rs
+++ b/src/wikidata.rs
@@ -226,10 +226,16 @@ fn fetch(
     })
 }
 
+/// How long one SPARQL call may take. Wikidata's query service answers in
+/// one to three seconds usually, but is a shared public service and has been
+/// measured at nine; two queries in a row need the room, and only the first
+/// call for a symbol pays it (the answer is cached for a week).
+const SPARQL_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
+
 /// `POST query=…` to a SPARQL endpoint, asking for SPARQL JSON.
 fn sparql(endpoint: &str, query: &str) -> Result<serde_json::Value, WikidataError> {
     let agent = ureq::Agent::config_builder()
-        .timeout_global(Some(std::time::Duration::from_secs(20)))
+        .timeout_global(Some(SPARQL_TIMEOUT))
         .build()
         .new_agent();
     let response = agent
@@ -237,7 +243,12 @@ fn sparql(endpoint: &str, query: &str) -> Result<serde_json::Value, WikidataErro
         .header("Accept", "application/sparql-results+json")
         .header("User-Agent", "genenetwork4 (+https://genenetwork.org)")
         .send_form([("query", query)])
-        .map_err(|error| WikidataError::Unavailable(format!("{endpoint}: {error}")))?;
+        .map_err(|error| {
+            WikidataError::Unavailable(format!(
+                "{endpoint}: {error} (gave up after {}s)",
+                SPARQL_TIMEOUT.as_secs()
+            ))
+        })?;
     response
         .into_body()
         .read_json::<serde_json::Value>()