feat: add fetch timeout
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use std::time::Duration;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use wasmtime::{Config, Engine, Instance, Linker, Module, Store};
|
use wasmtime::{Config, Engine, Instance, Linker, Module, Store};
|
||||||
@@ -15,6 +16,13 @@ struct JsResult {
|
|||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get(url: &str) -> reqwest::Result<reqwest::blocking::Response> {
|
||||||
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
.timeout(Duration::from_secs(8))
|
||||||
|
.build()?;
|
||||||
|
client.get(url).send()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MyContainer;
|
pub struct MyContainer;
|
||||||
|
|
||||||
@@ -23,7 +31,7 @@ impl container::Container for MyContainer {
|
|||||||
println!("fetch arguments: {}", s);
|
println!("fetch arguments: {}", s);
|
||||||
let url: String = s.chars().skip(1).take(s.len() - 2).collect();
|
let url: String = s.chars().skip(1).take(s.len() - 2).collect();
|
||||||
println!("fetch arguments URL: {}", url);
|
println!("fetch arguments URL: {}", url);
|
||||||
let r = match reqwest::blocking::get(&url) {
|
let r = match get(&url) {
|
||||||
Err(e) => return serde_json::to_string(&FetchResult {
|
Err(e) => return serde_json::to_string(&FetchResult {
|
||||||
error: Some(serde_json::to_string(&JsResult {
|
error: Some(serde_json::to_string(&JsResult {
|
||||||
message: format!("failed: {}", e)
|
message: format!("failed: {}", e)
|
||||||
@@ -109,6 +117,7 @@ fn default_config() -> Result<Config> {
|
|||||||
// Create an engine with caching enabled to assist with iteration in this project.
|
// Create an engine with caching enabled to assist with iteration in this project.
|
||||||
let mut config = Config::new();
|
let mut config = Config::new();
|
||||||
config.cache_config_load_default()?;
|
config.cache_config_load_default()?;
|
||||||
|
// config.debug_info(true);
|
||||||
config.wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable);
|
config.wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable);
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user