diff --git a/kitsune-job-runner/Cargo.toml b/kitsune-job-runner/Cargo.toml index b2e54e108..3506d18b6 100644 --- a/kitsune-job-runner/Cargo.toml +++ b/kitsune-job-runner/Cargo.toml @@ -12,7 +12,7 @@ license = false eula = false [dependencies] -athena = { path = "../lib/athena" } +athena = { path = "../lib/athena", features = ["redis"] } clap = { version = "4.5.4", features = ["derive", "wrap_help"] } color-eyre = "0.6.3" just-retry = { path = "../lib/just-retry" } diff --git a/kitsune/Cargo.toml b/kitsune/Cargo.toml index 20f6637bd..254a0e302 100644 --- a/kitsune/Cargo.toml +++ b/kitsune/Cargo.toml @@ -15,7 +15,7 @@ license = false eula = false [dependencies] -athena = { path = "../lib/athena" } +athena = { path = "../lib/athena", features = ["redis"] } argon2 = { version = "0.5.3", features = ["std"] } askama = { version = "0.12.1", features = [ "with-axum", diff --git a/lib/athena/Cargo.toml b/lib/athena/Cargo.toml index 4a5e56f4c..29feb49e3 100644 --- a/lib/athena/Cargo.toml +++ b/lib/athena/Cargo.toml @@ -5,25 +5,29 @@ edition.workspace = true version.workspace = true license = "MIT OR Apache-2.0" +[[example]] +name = "basic_queue" +required-features = ["redis"] + [dependencies] -ahash = "0.8.11" +ahash = { version = "0.8.11", optional = true } async-trait = "0.1.80" -either = { version = "1.11.0", default-features = false } +either = { version = "1.11.0", default-features = false, optional = true } futures-util = { version = "0.3.30", default-features = false } -iso8601-timestamp = { version = "0.2.17", features = ["diesel-pg"] } -just-retry = { path = "../just-retry" } -multiplex-pool = { path = "../multiplex-pool" } -once_cell = "1.19.0" -rand = "0.8.5" +iso8601-timestamp = "0.2.17" +just-retry = { path = "../just-retry", optional = true } +multiplex-pool = { path = "../multiplex-pool", optional = true } +once_cell = { version = "1.19.0", optional = true } +rand = { version = "0.8.5", optional = true } redis = { version = "0.25.3", default-features = false, features = [ "ahash", "connection-manager", "script", "streams", "tokio-comp", -] } -serde = { version = "1.0.198", features = ["derive"] } -simd-json = "0.13.10" +], optional = true } +serde = { version = "1.0.198", features = ["derive"], optional = true } +simd-json = { version = "0.13.10", optional = true } smol_str = "0.2.1" speedy-uuid = { path = "../speedy-uuid", features = ["redis", "serde"] } thiserror = "1.0.59" @@ -32,6 +36,19 @@ tokio-util = { version = "0.7.10", features = ["rt"] } tracing = "0.1.40" typed-builder = "0.18.2" +[features] +redis = [ + "dep:ahash", + "dep:either", + "dep:just-retry", + "dep:multiplex-pool", + "dep:once_cell", + "dep:rand", + "dep:redis", + "dep:serde", + "dep:simd-json", +] + [dev-dependencies] redis = { version = "0.25.3", features = ["connection-manager"] } tracing-subscriber = "0.3.18" diff --git a/lib/athena/src/error.rs b/lib/athena/src/error.rs index eb425dea8..3ccf423ec 100644 --- a/lib/athena/src/error.rs +++ b/lib/athena/src/error.rs @@ -9,9 +9,11 @@ pub enum Error { #[error(transparent)] ContextRepository(BoxError), + #[cfg(feature = "redis")] #[error(transparent)] Redis(#[from] redis::RedisError), + #[cfg(feature = "redis")] #[error(transparent)] SimdJson(#[from] simd_json::Error), diff --git a/lib/athena/src/lib.rs b/lib/athena/src/lib.rs index 6246b9be7..020d975e1 100644 --- a/lib/athena/src/lib.rs +++ b/lib/athena/src/lib.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "redis")] #[macro_use] extern crate tracing; @@ -9,23 +10,28 @@ use speedy_uuid::Uuid; use std::sync::Arc; use typed_builder::TypedBuilder; -pub use self::{error::Error, redis::JobQueue as RedisJobQueue}; +pub use self::error::Error; pub use tokio_util::task::TaskTracker; +#[cfg(feature = "redis")] +pub use self::redis::JobQueue as RedisJobQueue; + mod error; mod macros; +#[cfg(feature = "redis")] mod redis; #[derive(TypedBuilder)] +#[non_exhaustive] pub struct JobDetails { #[builder(setter(into))] - context: C, + pub context: C, #[builder(default)] - fail_count: u32, + pub fail_count: u32, #[builder(default = Uuid::now_v7(), setter(into))] - job_id: Uuid, + pub job_id: Uuid, #[builder(default, setter(into))] - run_at: Option, + pub run_at: Option, } #[async_trait]