Skip to content

Commit 311ac4a

Browse files
authored
chore: upgrade to ntex 3.0 (#1361)
* chore: upgrade to ntex 3.0 * fix: unit tests
1 parent 1a89f66 commit 311ac4a

File tree

50 files changed

+919
-504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+919
-504
lines changed

Cargo.lock

Lines changed: 587 additions & 299 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/nanocl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ serde_yaml = "0.9"
4444
tabled = "0.20"
4545
indicatif = "0.18"
4646
serde_json = "1.0"
47-
ntex = { version = "2", features = ["tokio", "openssl"] }
47+
ntex = { version = "3", features = ["tokio", "openssl"] }
4848
serde = { version = "1.0", features = ["derive"] }
4949
clap = { version = "4.5", features = ["derive", "cargo"] }
5050
tokio = { version = "1.49", features = ["fs"] }

bin/nanocl/src/utils/installer.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use ntex::http;
2-
31
use nanocl_error::http::HttpError;
42
use nanocl_error::http_client::{HttpClientError, HttpClientResult};
53
use nanocl_error::io::{FromIo, IoResult};
@@ -8,11 +6,11 @@ use crate::version::{CHANNEL, VERSION};
86

97
/// Get template from our GitHub repo for installation
108
async fn get() -> HttpClientResult<String> {
11-
let client = http::client::Client::new();
9+
let client = ntex::client::Client::new().await;
1210
let url = format!(
1311
"https://raw.githubusercontent.com/next-hat/nanocl/release/{CHANNEL}/bin/nanocl/{VERSION}/installer.yml"
1412
);
15-
let mut res = client.get(url).send().await.map_err(|err| {
13+
let res = client.get(url).send().await.map_err(|err| {
1614
err.map_err_context(|| "Unable to fetch installer template")
1715
})?;
1816
let status = res.status();

bin/nanocl/src/utils/liquid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl StateSource {
2626
.as_str()
2727
.to_owned();
2828
std::thread::spawn(move || {
29-
ntex::rt::System::new(&url)
29+
ntex::rt::System::new(&url, ntex::rt::DefaultRuntime)
3030
.block_on(async move { utils::state::download_statefile(&url).await })
3131
})
3232
.join()

bin/nanocl/src/utils/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub async fn download_statefile(url: &str) -> IoResult<(String, String)> {
2626
} else {
2727
format!("https://{url}")
2828
};
29-
let client = ntex::http::Client::default();
29+
let client = ntex::client::Client::new().await;
3030
let mut res = client
3131
.get(&url)
3232
.header("User-Agent", "nanocl")

bin/nanocld/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ clap = { version = "4.5", features = ["derive"] }
5959
url = { version = "2", features = ["serde"] }
6060
serde = { version = "1.0", features = ["derive"] }
6161
uuid = { version = "1.16", features = ["serde", "v4"] }
62-
ntex = { version = "2", features = ["tokio", "openssl"] }
62+
ntex = { version = "3", features = ["tokio", "openssl"] }
6363
diesel = { version = "2.3", features = [
6464
"postgres",
6565
"r2d2",
@@ -85,7 +85,7 @@ nanocl_stubs = { version = "0.17", features = ["serde", "clap"] }
8585
nanocl_utils = { version = "0.8", features = ["unix", "ntex", "logger"] }
8686
utoipa = { version = "5", features = ["yaml"], optional = true }
8787
notify = "8.0"
88-
ntex-cors = "2"
88+
ntex-cors = "3"
8989
rand = "0.9"
9090
openssl = { version = "0.10" }
9191
ipnet = { version = "2.10.0", features = ["serde"] }

bin/nanocld/src/repositories/distributed_mutex.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22

33
use diesel::prelude::*;
4-
use nanocl_error::io::IoResult;
4+
use nanocl_error::io::{IoError, IoResult};
55
use nanocl_stubs::generic::GenericFilter;
66

77
use crate::{
@@ -127,7 +127,13 @@ impl DistributedMutexDb {
127127
let item = query.get_result(&mut conn).map_err(Self::map_err)?;
128128
Ok(item)
129129
})
130-
.await?
130+
.await
131+
.map_err(|err| {
132+
IoError::interrupted(
133+
"Interrupted while getting lock",
134+
err.to_string().as_str(),
135+
)
136+
})?
131137
}
132138

133139
pub async fn del_lock(
@@ -148,6 +154,12 @@ impl DistributedMutexDb {
148154
query.execute(&mut conn).map_err(Self::map_err)?;
149155
Ok(())
150156
})
151-
.await?
157+
.await
158+
.map_err(|err| {
159+
IoError::interrupted(
160+
"Interrupted while deleting lock",
161+
err.to_string().as_str(),
162+
)
163+
})?
152164
}
153165
}

bin/nanocld/src/repositories/generic/create.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ pub trait RepositoryCreate: super::RepositoryBase {
2929
.map_err(Self::map_err)?;
3030
Ok(item)
3131
})
32-
.await?
32+
.await
33+
.map_err(|err| {
34+
IoError::interrupted(
35+
"Interrupted while creating item",
36+
err.to_string().as_str(),
37+
)
38+
})?
3339
}
3440

3541
async fn create_try_from<I>(item: I, pool: &Pool) -> IoResult<Self>

bin/nanocld/src/repositories/generic/delete.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use diesel::{associations::HasTable, prelude::*, query_builder, query_dsl};
22

3-
use nanocl_error::io::IoResult;
3+
use nanocl_error::io::{IoError, IoResult};
44

55
use nanocl_stubs::generic::GenericFilter;
66

@@ -32,7 +32,13 @@ pub trait RepositoryDelByPk: super::RepositoryBase {
3232
.map_err(Self::map_err)?;
3333
Ok(())
3434
})
35-
.await?
35+
.await
36+
.map_err(|err| {
37+
IoError::interrupted(
38+
"Interrupted while deleting item",
39+
err.to_string().as_str(),
40+
)
41+
})?
3642
}
3743
}
3844

@@ -65,6 +71,12 @@ pub trait RepositoryDelBy: super::RepositoryBase {
6571
query.execute(&mut conn).map_err(Self::map_err)?;
6672
Ok(())
6773
})
68-
.await?
74+
.await
75+
.map_err(|err| {
76+
IoError::interrupted(
77+
"Interrupted while deleting item",
78+
err.to_string().as_str(),
79+
)
80+
})?
6981
}
7082
}

bin/nanocld/src/repositories/generic/read.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use diesel::{prelude::*, query_dsl::methods::LoadQuery};
22

3-
use nanocl_error::io::IoResult;
3+
use nanocl_error::io::{IoError, IoResult};
44

55
use nanocl_stubs::generic::{GenericClause, GenericFilter};
66

@@ -38,7 +38,13 @@ pub trait RepositoryReadBy: super::RepositoryBase {
3838
.map_err(Self::map_err)?;
3939
Ok(item)
4040
})
41-
.await?
41+
.await
42+
.map_err(|err| {
43+
IoError::interrupted(
44+
"Interrupted while reading item",
45+
err.to_string().as_str(),
46+
)
47+
})?
4248
}
4349

4450
async fn read_by_pk<Pk>(pk: &Pk, pool: &Pool) -> IoResult<Self::Output>
@@ -71,7 +77,13 @@ pub trait RepositoryReadBy: super::RepositoryBase {
7177
.map_err(Self::map_err)?;
7278
Ok(items)
7379
})
74-
.await?
80+
.await
81+
.map_err(|err| {
82+
IoError::interrupted(
83+
"Interrupted while reading item",
84+
err.to_string().as_str(),
85+
)
86+
})?
7587
}
7688
}
7789

@@ -139,6 +151,12 @@ pub trait RepositoryCountBy: RepositoryBase {
139151
.map_err(Self::map_err)?;
140152
Ok(count)
141153
})
142-
.await?
154+
.await
155+
.map_err(|err| {
156+
IoError::interrupted(
157+
"Interrupted while reading item",
158+
err.to_string().as_str(),
159+
)
160+
})?
143161
}
144162
}

0 commit comments

Comments
 (0)