Skip to content

Commit 04e5d62

Browse files
committed
Remove civet server option
1 parent 094188b commit 04e5d62

File tree

4 files changed

+37
-85
lines changed

4 files changed

+37
-85
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ anyhow = "1.0"
3434
base64 = "0.13"
3535
cargo-registry-s3 = { path = "src/s3", version = "0.2.0" }
3636
chrono = { version = "0.4.0", features = ["serde"] }
37-
civet = "0.12.0-alpha.5"
3837
clap = "=3.0.0-beta.2"
3938
comrak = { version = "0.9", default-features = false }
4039

docs/BACKEND.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ The server does the following things:
1212
3. Reads values from environment variables to configure a new instance of `cargo_registry::App`
1313
4. Adds middleware to the app by calling `cargo_registry::middleware`
1414
5. Syncs the categories defined in *src/categories.toml* with the categories in the database
15-
6. Starts either a [conduit] or a [hyper] server that uses the `cargo_registry::App` instance
15+
6. Starts a [hyper] server that uses the `cargo_registry::App` instance
1616
7. Tells Nginx on Heroku that the application is ready to receive requests, if running on Heroku
1717
8. Blocks forever (or until the process is killed)
1818

19-
[civet]: https://crates.io/crates/civet
2019
[hyper]: https://crates.io/crates/hyper
2120

2221
## Routes

src/bin/server.rs

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,15 @@ use std::{
1010
time::Duration,
1111
};
1212

13-
use civet::Server as CivetServer;
1413
use conduit_hyper::Service;
1514
use futures_util::future::FutureExt;
1615
use reqwest::blocking::Client;
1716
use sentry::{ClientOptions, IntoDsn};
17+
use tokio::io::AsyncWriteExt;
18+
use tokio::signal::unix::{signal, SignalKind};
1819

1920
const CORE_THREADS: usize = 4;
2021

21-
#[allow(clippy::large_enum_variant)]
22-
enum Server {
23-
Civet(CivetServer),
24-
Hyper(tokio::runtime::Runtime, tokio::task::JoinHandle<()>),
25-
}
26-
27-
use Server::*;
28-
2922
fn main() -> Result<(), Box<dyn std::error::Error>> {
3023
let _sentry = dotenv::var("SENTRY_DSN_API")
3124
.ok()
@@ -90,52 +83,41 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
9083
}
9184
});
9285

93-
let server = if dotenv::var("WEB_USE_CIVET").is_err() {
94-
use tokio::io::AsyncWriteExt;
95-
use tokio::signal::unix::{signal, SignalKind};
96-
97-
println!("Booting with a hyper based server");
98-
99-
let rt = tokio::runtime::Builder::new_multi_thread()
100-
.enable_all()
101-
.worker_threads(CORE_THREADS)
102-
.max_blocking_threads(threads as usize)
103-
.build()
104-
.unwrap();
105-
106-
let handler = Arc::new(conduit_hyper::BlockingHandler::new(handler));
107-
let make_service =
108-
hyper::service::make_service_fn(move |socket: &hyper::server::conn::AddrStream| {
109-
let addr = socket.remote_addr();
110-
let handler = handler.clone();
111-
async move { Service::from_blocking(handler, addr) }
112-
});
113-
114-
let addr = (ip, port).into();
115-
#[allow(clippy::async_yields_async)]
116-
let server = rt.block_on(async { hyper::Server::bind(&addr).serve(make_service) });
117-
118-
let mut sig_int = rt.block_on(async { signal(SignalKind::interrupt()) })?;
119-
let mut sig_term = rt.block_on(async { signal(SignalKind::terminate()) })?;
120-
121-
let server = server.with_graceful_shutdown(async move {
122-
// Wait for either signal
123-
futures_util::select! {
124-
_ = sig_int.recv().fuse() => {},
125-
_ = sig_term.recv().fuse() => {},
126-
};
127-
let mut stdout = tokio::io::stdout();
128-
stdout.write_all(b"Starting graceful shutdown\n").await.ok();
86+
println!("Booting with a hyper based server");
87+
88+
let rt = tokio::runtime::Builder::new_multi_thread()
89+
.enable_all()
90+
.worker_threads(CORE_THREADS)
91+
.max_blocking_threads(threads as usize)
92+
.build()
93+
.unwrap();
94+
95+
let handler = Arc::new(conduit_hyper::BlockingHandler::new(handler));
96+
let make_service =
97+
hyper::service::make_service_fn(move |socket: &hyper::server::conn::AddrStream| {
98+
let addr = socket.remote_addr();
99+
let handler = handler.clone();
100+
async move { Service::from_blocking(handler, addr) }
129101
});
130102

131-
let server = rt.spawn(async { server.await.unwrap() });
132-
Hyper(rt, server)
133-
} else {
134-
println!("Booting with a civet based server");
135-
let mut cfg = civet::Config::new();
136-
cfg.port(port).threads(threads).keep_alive(true);
137-
Civet(CivetServer::start(cfg, handler).unwrap())
138-
};
103+
let addr = (ip, port).into();
104+
#[allow(clippy::async_yields_async)]
105+
let server = rt.block_on(async { hyper::Server::bind(&addr).serve(make_service) });
106+
107+
let mut sig_int = rt.block_on(async { signal(SignalKind::interrupt()) })?;
108+
let mut sig_term = rt.block_on(async { signal(SignalKind::terminate()) })?;
109+
110+
let server = server.with_graceful_shutdown(async move {
111+
// Wait for either signal
112+
futures_util::select! {
113+
_ = sig_int.recv().fuse() => {},
114+
_ = sig_term.recv().fuse() => {},
115+
};
116+
let mut stdout = tokio::io::stdout();
117+
stdout.write_all(b"Starting graceful shutdown\n").await.ok();
118+
});
119+
120+
let server = rt.spawn(async { server.await.unwrap() });
139121

140122
println!("listening on port {}", port);
141123

@@ -159,17 +141,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
159141
}
160142

161143
// Block the main thread until the server has shutdown
162-
match server {
163-
Hyper(rt, server) => {
164-
rt.block_on(async { server.await.unwrap() });
165-
}
166-
Civet(server) => {
167-
let (tx, rx) = channel::<()>();
168-
ctrlc_handler(move || tx.send(()).unwrap_or(()));
169-
rx.recv().unwrap();
170-
drop(server);
171-
}
172-
}
144+
rt.block_on(async { server.await.unwrap() });
173145

174146
println!("Persisting remaining downloads counters");
175147
if let Err(err) = app.downloads_counter.persist_all_shards(&app) {

0 commit comments

Comments
 (0)