diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 2decb065a..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "rust-analyzer.cargo.features": "all" -} diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 85df6bb11..dd63682b4 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -13,12 +13,12 @@ check-if-email-exists = { path = "../core", features = ["sentry"] } config = "0.14" csv = "1.3.0" dotenv = "0.15.0" -futures = { version = "0.3.30", optional = true } -lapin = { version = "2.3.1", optional = true } -tokio-executor-trait = { version = "2.1.1", optional = true } -tokio-reactor-trait = { version = "1.1.0", optional = true } +futures = { version = "0.3.30" } +lapin = { version = "2.3.1" } +tokio-executor-trait = { version = "2.1.1" } +tokio-reactor-trait = { version = "1.1.0" } openssl = { version = "0.10.64", features = ["vendored"] } -reqwest = { version = "0.12.5", features = ["json", "socks"], optional = true } +reqwest = { version = "0.12.5", features = ["json", "socks"] } sentry = "0.23" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" @@ -40,12 +40,3 @@ warp = "0.3" [dev-dependencies] toml = "0.8" - -[features] -worker = [ - "futures", - "lapin", - "tokio-executor-trait", - "tokio-reactor-trait", - "reqwest", -] diff --git a/backend/Dockerfile b/backend/Dockerfile index 14c7fcd56..dc9393a45 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -14,7 +14,7 @@ COPY . . ENV SQLX_OFFLINE=true -RUN cargo build --bin reacher_backend --features worker --release --target=x86_64-unknown-linux-musl +RUN cargo build --bin reacher_backend --release --target=x86_64-unknown-linux-musl # ------------------------------------------------------------------------------ # Final Stage diff --git a/backend/README.md b/backend/README.md index 166d8a91e..b5c21c6ee 100644 --- a/backend/README.md +++ b/backend/README.md @@ -57,7 +57,7 @@ $ git clone https://github.com/reacherhq/check-if-email-exists $ cd check-if-email-exists/backend # Run the backend binary in release mode (slower build, but more performant). -$ cargo run --release --bin reacher_backend --features worker +$ cargo run --release --bin reacher_backend ``` The server will then be listening on `http://127.0.0.1:8080`. diff --git a/backend/src/config.rs b/backend/src/config.rs index 1a4f2dbce..80f67b1a9 100644 --- a/backend/src/config.rs +++ b/backend/src/config.rs @@ -15,9 +15,7 @@ // along with this program. If not, see . use crate::storage::{postgres::PostgresStorage, Storage}; -#[cfg(feature = "worker")] use crate::worker::do_work::TaskWebhook; -#[cfg(feature = "worker")] use crate::worker::setup_rabbit_mq; use anyhow::{bail, Context}; use check_if_email_exists::{ @@ -25,11 +23,9 @@ use check_if_email_exists::{ YahooVerifMethod, LOG_TARGET, }; use config::Config; -#[cfg(feature = "worker")] use lapin::Channel; use serde::{Deserialize, Serialize}; use sqlx::PgPool; -#[cfg(feature = "worker")] use std::sync::Arc; use std::{any::Any, collections::HashMap}; use tracing::warn; @@ -68,7 +64,6 @@ pub struct BackendConfig { pub storage: HashMap, // Internal fields, not part of the configuration. - #[cfg(feature = "worker")] #[serde(skip)] channel: Option>, @@ -87,19 +82,16 @@ impl BackendConfig { self.worker.enable, &self.worker.throttle, &self.worker.rabbitmq, - #[cfg(feature = "worker")] &self.channel, ) { - #[cfg(feature = "worker")] (true, Some(throttle), Some(rabbitmq), Some(channel)) => Ok(MustWorkerConfig { - #[cfg(feature = "worker")] channel: channel.clone(), throttle: throttle.clone(), rabbitmq: rabbitmq.clone(), - #[cfg(feature = "worker")] + webhook: self.worker.webhook.clone(), }), - #[cfg(feature = "worker")] + (true, _, _, _) => bail!("Worker configuration is missing"), _ => bail!("Calling must_worker_config on a non-worker backend"), } @@ -123,19 +115,16 @@ impl BackendConfig { } } - #[cfg(feature = "worker")] - { - let channel = if self.worker.enable { - let rabbitmq_config = self.worker.rabbitmq.as_ref().ok_or_else(|| { - anyhow::anyhow!("Worker configuration is missing the rabbitmq configuration") - })?; - let channel = setup_rabbit_mq(&self.backend_name, rabbitmq_config).await?; - Some(Arc::new(channel)) - } else { - None - }; - self.channel = channel; - } + let channel = if self.worker.enable { + let rabbitmq_config = self.worker.rabbitmq.as_ref().ok_or_else(|| { + anyhow::anyhow!("Worker configuration is missing the rabbitmq configuration") + })?; + let channel = setup_rabbit_mq(&self.backend_name, rabbitmq_config).await?; + Some(Arc::new(channel)) + } else { + None + }; + self.channel = channel; Ok(()) } @@ -179,7 +168,6 @@ pub struct WorkerConfig { pub throttle: Option, pub rabbitmq: Option, /// Optional webhook configuration to send email verification results. - #[cfg(feature = "worker")] pub webhook: Option, } @@ -187,12 +175,10 @@ pub struct WorkerConfig { /// a domain type to ensure that the worker configuration is present. #[derive(Debug, Clone)] pub struct MustWorkerConfig { - #[cfg(feature = "worker")] pub channel: Arc, pub throttle: ThrottleConfig, pub rabbitmq: RabbitMQConfig, - #[cfg(feature = "worker")] pub webhook: Option, } diff --git a/backend/src/http/error.rs b/backend/src/http/error.rs index ac4c01278..0428994f5 100644 --- a/backend/src/http/error.rs +++ b/backend/src/http/error.rs @@ -77,7 +77,6 @@ impl From for ReacherResponseError { } } -#[cfg(feature = "worker")] impl From for ReacherResponseError { fn from(e: lapin::Error) -> Self { ReacherResponseError::new(StatusCode::INTERNAL_SERVER_ERROR, e) diff --git a/backend/src/http/mod.rs b/backend/src/http/mod.rs index fdd6a20fd..e94f62f2a 100644 --- a/backend/src/http/mod.rs +++ b/backend/src/http/mod.rs @@ -16,7 +16,6 @@ mod error; mod v0; -#[cfg(feature = "worker")] mod v1; mod version; @@ -38,7 +37,8 @@ pub fn create_routes( config: Arc, ) -> impl Filter + Clone { let pg_pool = config.get_pg_pool(); - let t = version::get::get_version() + + version::get::get_version() .or(v0::check_email::post::post_check_email(Arc::clone(&config))) // The 3 following routes will 404 if o is None. .or(v0::bulk::post::create_bulk_job( @@ -46,23 +46,14 @@ pub fn create_routes( pg_pool.clone(), )) .or(v0::bulk::get::get_bulk_job_status(pg_pool.clone())) - .or(v0::bulk::results::get_bulk_job_result(pg_pool)); - - #[cfg(feature = "worker")] - { - t.or(v1::check_email::post::v1_check_email(Arc::clone(&config))) - .or(v1::bulk::post::v1_create_bulk_job(Arc::clone(&config))) - .or(v1::bulk::get_progress::v1_get_bulk_job_progress( - Arc::clone(&config), - )) - .or(v1::bulk::get_results::v1_get_bulk_job_results(config)) - .recover(handle_rejection) - } - - #[cfg(not(feature = "worker"))] - { - t.recover(handle_rejection) - } + .or(v0::bulk::results::get_bulk_job_result(pg_pool)) + .or(v1::check_email::post::v1_check_email(Arc::clone(&config))) + .or(v1::bulk::post::v1_create_bulk_job(Arc::clone(&config))) + .or(v1::bulk::get_progress::v1_get_bulk_job_progress( + Arc::clone(&config), + )) + .or(v1::bulk::get_results::v1_get_bulk_job_results(config)) + .recover(handle_rejection) } /// Runs the Warp server. diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 5b5afad63..71c140ccf 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -17,7 +17,6 @@ pub mod config; pub mod http; mod storage; -#[cfg(feature = "worker")] pub mod worker; const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/backend/src/main.rs b/backend/src/main.rs index 2a262b82b..e815cd62b 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -20,7 +20,6 @@ use check_if_email_exists::{setup_sentry, LOG_TARGET}; use reacher_backend::config::load_config; use reacher_backend::http::run_warp_server; -#[cfg(feature = "worker")] use reacher_backend::worker::run_worker; use std::sync::Arc; use tracing::{debug, info}; @@ -45,25 +44,17 @@ async fn main() -> Result<(), anyhow::Error> { let config = Arc::new(config); - #[cfg(feature = "worker")] - { - let server_future = run_warp_server(Arc::clone(&config)); - let worker_future = async { - if config.worker.enable { - run_worker(config).await?; - } - Ok(()) - }; + let server_future = run_warp_server(Arc::clone(&config)); + let worker_future = async { + if config.worker.enable { + run_worker(config).await?; + } + Ok(()) + }; - tokio::try_join!(server_future, worker_future)?; + tokio::try_join!(server_future, worker_future)?; - info!("Shutting down..."); - } - - #[cfg(not(feature = "worker"))] - { - run_warp_server(config).await?; - } + info!("Shutting down..."); Ok(()) }