diff --git a/Cargo.lock b/Cargo.lock index 20aee949777cf89e6d52dc6266796c82907fce5c..20fccd0b94f896f5af7b123924c8360411397fad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2762,7 +2762,6 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b555e70fbbf84e269ec3858b7a6515bcfe7a166a7cc9c636dd6efd20431678b6" dependencies = [ - "actix-rt", "once_cell", "tokio", "tokio-rustls", @@ -3087,6 +3086,7 @@ dependencies = [ "pin-project-lite", "signal-hook-registry", "socket2", + "tokio-macros", "winapi", ] @@ -3101,6 +3101,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-macros" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tokio-native-tls" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index e70ca6515b7577ac1f6a644bdcb1f1bac039ad9e..84bffee98151a600cb4e6675cbeda3091cbe0131 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ version = "^0.7.0" [dependencies.rbatis] default-features = false -features = ["runtime-actix-rustls", "all-database"] +features = ["runtime-tokio-rustls", "all-database"] optional = true version = "^3.0" @@ -83,7 +83,7 @@ features = ["derive"] version = "0.23" [dependencies.tokio] -features = ["time", "process", "fs", "io-std", "io-util", "rt-multi-thread", "bytes"] +features = ["time", "process", "fs", "io-std", "io-util", "rt-multi-thread", "bytes", "rt", "macros"] version = "1.4.0" [dependencies.tokio-amqp] diff --git a/src/info_storages/file_info_storage.rs b/src/info_storages/file_info_storage.rs index a2cdf351b933153d29e310944c10d150d1adcc72..461ca73b5fa276af0089a6cd618356343e13398c 100644 --- a/src/info_storages/file_info_storage.rs +++ b/src/info_storages/file_info_storage.rs @@ -45,7 +45,7 @@ impl InfoStorage for FileInfoStorage { async fn set_info(&self, file_info: &FileInfo, create: bool) -> RustusResult<()> { let info = file_info.clone(); let path = self.info_file_path(info.id.as_str()); - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { let file = OpenOptions::new() .write(true) .create(create) @@ -68,7 +68,7 @@ impl InfoStorage for FileInfoStorage { async fn get_info(&self, file_id: &str) -> RustusResult<FileInfo> { let info_path = self.info_file_path(file_id); - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { if !info_path.exists() { return Err(RustusError::FileNotFound); } @@ -84,7 +84,7 @@ impl InfoStorage for FileInfoStorage { async fn remove_info(&self, file_id: &str) -> RustusResult<()> { let id = String::from(file_id); let info_path = self.info_file_path(id.as_str()); - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { if !info_path.exists() { return Err(RustusError::FileNotFound); } diff --git a/src/info_storages/models/file_info.rs b/src/info_storages/models/file_info.rs index 42089ab3f7eee772dd8cc77fab40d27e4d361095..e1dbc45f4f6746500c80c4eb4149d98220b3ec66 100644 --- a/src/info_storages/models/file_info.rs +++ b/src/info_storages/models/file_info.rs @@ -91,7 +91,7 @@ impl FileInfo { pub async fn json(&self) -> RustusResult<String> { let info_clone = self.clone(); - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { serde_json::to_string(&info_clone).map_err(RustusError::from) }) .await @@ -102,7 +102,7 @@ impl FileInfo { } pub async fn from_json(data: String) -> RustusResult<Self> { - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { serde_json::from_str::<Self>(data.as_str()).map_err(RustusError::from) }) .await diff --git a/src/main.rs b/src/main.rs index 400db9f634bc7efa98514cc4047095d7291a6821..16713c62440ab5438afe459584457a7d2bdb3ac3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,7 +135,7 @@ fn setup_logging(app_config: &RustusConf) -> RustusResult<()> { /// Main program entrypoint. #[cfg_attr(coverage, no_coverage)] -#[actix_web::main] +#[tokio::main] async fn main() -> std::io::Result<()> { let app_conf = RustusConf::from_args(); // Configuring logging. diff --git a/src/protocol/core/write_bytes.rs b/src/protocol/core/write_bytes.rs index 93cf9000bbdaeb8b632301907866ccd2a936a483..49418abfcca6a3b82f1bdb1faddba87b9b7f16a1 100644 --- a/src/protocol/core/write_bytes.rs +++ b/src/protocol/core/write_bytes.rs @@ -105,7 +105,7 @@ pub async fn write_bytes( .hooks_format .format(&request, &file_info)?; let headers = request.headers().clone(); - actix_web::rt::spawn(async move { + tokio::task::spawn_local(async move { state .notification_manager .send_message(message, hook, &headers) diff --git a/src/protocol/creation/routes.rs b/src/protocol/creation/routes.rs index c11fe66199e1efe4d8029561b9d7f92d7ef28d07..86c8b3440e421694db23a60c5b50164b3bdfc196 100644 --- a/src/protocol/creation/routes.rs +++ b/src/protocol/creation/routes.rs @@ -200,7 +200,7 @@ pub async fn create_file( let headers = request.headers().clone(); // Adding send_message task to tokio reactor. // Thin function would be executed in background. - actix_web::rt::spawn(async move { + tokio::task::spawn_local(async move { state .notification_manager .send_message(message, Hook::PostCreate, &headers) diff --git a/src/protocol/termination/routes.rs b/src/protocol/termination/routes.rs index 8da92a2a941570621cf593f949f3d77a8b8e6c23..31a5df31015d62e77ba0a962e08cd83507f58fcd 100644 --- a/src/protocol/termination/routes.rs +++ b/src/protocol/termination/routes.rs @@ -29,7 +29,7 @@ pub async fn terminate( .hooks_format .format(&request, &file_info)?; let headers = request.headers().clone(); - actix_web::rt::spawn(async move { + tokio::task::spawn_local(async move { state .notification_manager .send_message(message, Hook::PostTerminate, &headers) diff --git a/src/storages/file_storage.rs b/src/storages/file_storage.rs index 537378fc68b3826852ad10bee628df4df41ad734..86bf09d2c474b879ed7cedc200e22388bf077aef 100644 --- a/src/storages/file_storage.rs +++ b/src/storages/file_storage.rs @@ -89,7 +89,7 @@ impl Storage for FileStorage { } let path = String::from(file_info.path.as_ref().unwrap()); let force_sync = self.force_fsync; - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { // Opening file in w+a mode. // It means that we're going to append some // bytes to the end of a file. @@ -121,7 +121,7 @@ impl Storage for FileStorage { let info = file_info.clone(); // New path to file. let file_path = self.data_file_path(info.id.as_str())?; - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { // Creating new file. OpenOptions::new() .create(true) @@ -144,7 +144,7 @@ impl Storage for FileStorage { parts_info: Vec<FileInfo>, ) -> RustusResult<()> { let info = file_info.clone(); - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { let mut file = OpenOptions::new() .write(true) .append(true) @@ -172,7 +172,7 @@ impl Storage for FileStorage { async fn remove_file(&self, file_info: &FileInfo) -> RustusResult<()> { let info = file_info.clone(); - actix_web::rt::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { // Let's remove the file itself. let data_path = PathBuf::from(info.path.as_ref().unwrap().clone()); if !data_path.exists() {