From 745e990fa04561ce0137e38c01bc628215c7b44f Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 24 Sep 2023 15:45:10 -0500 Subject: [PATCH] Remove direct dependency on actix-rt and actix-server --- Cargo.lock | 16 ++++++++++++++-- Cargo.toml | 6 ++---- src/file.rs | 4 ++-- src/future.rs | 4 ++-- src/ingest/hasher.rs | 4 ++-- src/lib.rs | 2 +- src/main.rs | 2 +- src/middleware.rs | 2 +- src/migrate_store.rs | 4 ++-- src/process.rs | 6 +++--- src/queue.rs | 6 +++--- src/repo/postgres.rs | 2 +- src/repo/sled.rs | 4 ++-- src/repo_04/sled.rs | 4 ++-- src/store/object_store.rs | 2 +- src/stream.rs | 2 +- src/sync.rs | 8 ++++---- 17 files changed, 44 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33e4a68..e567df0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,11 +175,13 @@ checksum = "0e4a5b5e29603ca8c94a77c65cf874718ceb60292c5a5c3e5f4ace041af462b9" dependencies = [ "actix-codec", "actix-http", + "actix-macros", "actix-router", "actix-rt", "actix-server", "actix-service", "actix-utils", + "actix-web-codegen", "ahash 0.8.3", "bytes", "bytestring", @@ -204,6 +206,18 @@ dependencies = [ "url", ] +[[package]] +name = "actix-web-codegen" +version = "4.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb1f50ebbb30eca122b188319a4398b3f7bb4a8cdf50ecfb73bfc6a3c3ce54f5" +dependencies = [ + "actix-router", + "proc-macro2", + "quote", + "syn 2.0.31", +] + [[package]] name = "addr2line" version = "0.21.0" @@ -1804,8 +1818,6 @@ name = "pict-rs" version = "0.5.0-alpha.17" dependencies = [ "actix-form-data", - "actix-rt", - "actix-server", "actix-web", "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 4d21f23..fcc3f4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] default = [] -io-uring = ["actix-rt/io-uring", "actix-server/io-uring", "tokio-uring", "sled/io_uring"] +io-uring = ["dep:tokio-uring", "sled/io_uring", "actix-web/experimental-io-uring"] [dependencies] actix-form-data = "0.7.0-beta.4" -actix-rt = { version = "2.7.0", default-features = false } -actix-server = "2.0.0" -actix-web = { version = "4.0.0", default-features = false } +actix-web = { version = "4.0.0", default-features = false, features = ["macros"] } anyhow = "1.0" async-trait = "0.1.51" barrel = { version = "0.7.0", features = ["pg"] } diff --git a/src/file.rs b/src/file.rs index a2408df..093c26f 100644 --- a/src/file.rs +++ b/src/file.rs @@ -380,8 +380,8 @@ mod io_uring { macro_rules! test_on_arbiter { ($fut:expr) => { - actix_rt::System::new().block_on(async move { - let arbiter = actix_rt::Arbiter::new(); + actix_web::rt::System::new().block_on(async move { + let arbiter = actix_web::rt::Arbiter::new(); let (tx, rx) = crate::sync::channel(1); diff --git a/src/future.rs b/src/future.rs index aea858d..a89d857 100644 --- a/src/future.rs +++ b/src/future.rs @@ -6,11 +6,11 @@ use std::{ pub(crate) type LocalBoxFuture<'a, T> = std::pin::Pin + 'a>>; pub(crate) trait WithTimeout: Future { - fn with_timeout(self, duration: Duration) -> actix_rt::time::Timeout + fn with_timeout(self, duration: Duration) -> actix_web::rt::time::Timeout where Self: Sized, { - actix_rt::time::timeout(duration, self) + actix_web::rt::time::timeout(duration, self) } } diff --git a/src/ingest/hasher.rs b/src/ingest/hasher.rs index 6466e10..d7577c2 100644 --- a/src/ingest/hasher.rs +++ b/src/ingest/hasher.rs @@ -79,8 +79,8 @@ mod test { macro_rules! test_on_arbiter { ($fut:expr) => { - actix_rt::System::new().block_on(async move { - let arbiter = actix_rt::Arbiter::new(); + actix_web::rt::System::new().block_on(async move { + let arbiter = actix_web::rt::Arbiter::new(); let (tx, rx) = crate::sync::channel(1); diff --git a/src/lib.rs b/src/lib.rs index b4da77d..d07e6a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1707,7 +1707,7 @@ fn spawn_cleanup(repo: ArcRepo, config: &Configuration) { } crate::sync::spawn(async move { - let mut interval = actix_rt::time::interval(Duration::from_secs(30)); + let mut interval = actix_web::rt::time::interval(Duration::from_secs(30)); loop { interval.tick().await; diff --git a/src/main.rs b/src/main.rs index 20aee47..af565d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -#[actix_rt::main] +#[actix_web::main] async fn main() -> color_eyre::Result<()> { pict_rs::PictRsConfiguration::build_default()? .install_tracing()? diff --git a/src/middleware.rs b/src/middleware.rs index 95c8846..27dc99e 100644 --- a/src/middleware.rs +++ b/src/middleware.rs @@ -1,9 +1,9 @@ mod metrics; -use actix_rt::time::Timeout; use actix_web::{ dev::{Service, ServiceRequest, Transform}, http::StatusCode, + rt::time::Timeout, HttpResponse, ResponseError, }; use std::{ diff --git a/src/migrate_store.rs b/src/migrate_store.rs index 3b47812..b0b0fe1 100644 --- a/src/migrate_store.rs +++ b/src/migrate_store.rs @@ -62,7 +62,7 @@ where tracing::warn!("Retrying migration +{failure_count}"); } - actix_rt::time::sleep(Duration::from_secs(3)).await; + actix_web::rt::time::sleep(Duration::from_secs(3)).await; } Ok(()) @@ -366,7 +366,7 @@ where tracing::warn!("Failed moving file. Retrying +{failure_count}"); } - actix_rt::time::sleep(Duration::from_secs(3)).await; + actix_web::rt::time::sleep(Duration::from_secs(3)).await; } } } diff --git a/src/process.rs b/src/process.rs index 61cd538..fb81ecf 100644 --- a/src/process.rs +++ b/src/process.rs @@ -1,4 +1,4 @@ -use actix_rt::task::JoinHandle; +use actix_web::rt::task::JoinHandle; use actix_web::web::Bytes; use flume::r#async::RecvFut; use std::{ @@ -78,7 +78,7 @@ pub(crate) struct ProcessRead { #[allow(dead_code)] handle: DropHandle, eof: bool, - sleep: Pin>, + sleep: Pin>, } #[derive(Debug, thiserror::Error)] @@ -238,7 +238,7 @@ impl Process { .instrument(span), ); - let sleep = actix_rt::time::sleep(timeout); + let sleep = actix_web::rt::time::sleep(timeout); ProcessRead { inner: stdout, diff --git a/src/queue.rs b/src/queue.rs index 8225d8b..94488ba 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -207,7 +207,7 @@ async fn process_jobs( tracing::warn!("{}", format!("{e:?}")); if e.is_disconnected() { - actix_rt::time::sleep(Duration::from_secs(10)).await; + actix_web::rt::time::sleep(Duration::from_secs(10)).await; } continue; @@ -341,7 +341,7 @@ async fn process_image_jobs( tracing::warn!("{}", format!("{e:?}")); if e.is_disconnected() { - actix_rt::time::sleep(Duration::from_secs(3)).await; + actix_web::rt::time::sleep(Duration::from_secs(3)).await; } continue; @@ -421,7 +421,7 @@ where let mut fut = std::pin::pin!(fut.instrument(tracing::info_span!("job-future", job_id = ?job_id))); - let mut interval = actix_rt::time::interval(Duration::from_secs(5)); + let mut interval = actix_web::rt::time::interval(Duration::from_secs(5)); let mut hb = None; diff --git a/src/repo/postgres.rs b/src/repo/postgres.rs index 99f0b3e..b020027 100644 --- a/src/repo/postgres.rs +++ b/src/repo/postgres.rs @@ -50,7 +50,7 @@ use super::{ pub(crate) struct PostgresRepo { inner: Arc, #[allow(dead_code)] - notifications: Arc>, + notifications: Arc>, } struct Inner { diff --git a/src/repo/sled.rs b/src/repo/sled.rs index 77eb054..632e5eb 100644 --- a/src/repo/sled.rs +++ b/src/repo/sled.rs @@ -1537,8 +1537,8 @@ impl std::fmt::Debug for SledRepo { } } -impl From for SledError { - fn from(_: actix_rt::task::JoinError) -> Self { +impl From for SledError { + fn from(_: actix_web::rt::task::JoinError) -> Self { SledError::Panic } } diff --git a/src/repo_04/sled.rs b/src/repo_04/sled.rs index 07ccd9e..3bef434 100644 --- a/src/repo_04/sled.rs +++ b/src/repo_04/sled.rs @@ -316,8 +316,8 @@ impl std::fmt::Debug for SledRepo { } } -impl From for SledError { - fn from(_: actix_rt::task::JoinError) -> Self { +impl From for SledError { + fn from(_: actix_web::rt::task::JoinError) -> Self { SledError::Panic } } diff --git a/src/store/object_store.rs b/src/store/object_store.rs index c639462..2985e51 100644 --- a/src/store/object_store.rs +++ b/src/store/object_store.rs @@ -2,13 +2,13 @@ use crate::{ bytes_stream::BytesStream, error_code::ErrorCode, future::WithMetrics, repo::ArcRepo, store::Store, stream::LocalBoxStream, }; -use actix_rt::task::JoinError; use actix_web::{ error::BlockingError, http::{ header::{ByteRangeSpec, Range, CONTENT_LENGTH}, StatusCode, }, + rt::task::JoinError, web::Bytes, }; use base64::{prelude::BASE64_STANDARD, Engine}; diff --git a/src/stream.rs b/src/stream.rs index 54c19a7..a9b1f10 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -148,7 +148,7 @@ where S::Item: 'static, { streem::try_from_fn(|yielder| async move { - actix_rt::time::timeout(duration, async move { + actix_web::rt::time::timeout(duration, async move { let stream = std::pin::pin!(stream); let mut streamer = stream.into_streamer(); diff --git a/src/sync.rs b/src/sync.rs index 10cc861..059b19c 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -23,16 +23,16 @@ pub(crate) fn bare_semaphore(permits: usize) -> Semaphore { } #[track_caller] -pub(crate) fn spawn(future: F) -> actix_rt::task::JoinHandle +pub(crate) fn spawn(future: F) -> actix_web::rt::task::JoinHandle where F: std::future::Future + 'static, F::Output: 'static, { - tracing::trace_span!(parent: None, "spawn task").in_scope(|| actix_rt::spawn(future)) + tracing::trace_span!(parent: None, "spawn task").in_scope(|| actix_web::rt::spawn(future)) } #[track_caller] -pub(crate) fn spawn_blocking(function: F) -> actix_rt::task::JoinHandle +pub(crate) fn spawn_blocking(function: F) -> actix_web::rt::task::JoinHandle where F: FnOnce() -> Out + Send + 'static, Out: Send + 'static, @@ -40,5 +40,5 @@ where let outer_span = tracing::Span::current(); tracing::trace_span!(parent: None, "spawn blocking task") - .in_scope(|| actix_rt::task::spawn_blocking(move || outer_span.in_scope(function))) + .in_scope(|| actix_web::rt::task::spawn_blocking(move || outer_span.in_scope(function))) }