Commit 93c97ca5 authored by Kornel's avatar Kornel
Browse files

Rewrite using Actix 2

parent 0b93021a
use std::collections::HashSet;
use std::collections::HashMap;
use crate_db::builddb::*;
......@@ -82,7 +83,8 @@ fn prepare_docker(docker_root: &Path) -> Result<(), Box<dyn std::error::Error>>
fn do_builds(_crates: &KitchenSink, all: &CratesIndexCrate, docker_root: &Path) -> Result<(String, String), Box<dyn std::error::Error>> {
let mut versions = HashMap::new();
for ver in all.versions().iter().filter(|v| !v.is_yanked()).filter_map(|v| SemVer::parse(v.version()).ok()) {
let tmp: HashSet<_> = all.versions().iter().filter(|v| !v.is_yanked()).filter_map(|v| SemVer::parse(v.version()).ok()).collect();
for ver in tmp.iter() {
let unstable = ver.major == 0;
let major = if unstable {ver.minor} else {ver.major};
versions.insert((unstable, major), ver); // later wins
......
[package]
name = "crates-server"
version = "0.8.5"
version = "0.9.0"
authors = ["Kornel <kornel@geekhood.net>"]
edition = "2018"
description = "Crates.rs web server"
......@@ -15,11 +15,9 @@ assets = [
]
[dependencies]
actix-web = "0.7.16"
actix-web = "2"
env_logger = "0.7"
log = "0.4.6"
futures-cpupool = "0.1.8"
futures = "0.1.25"
render_readme = { git = "https://gitlab.com/crates.rs/render_readme.git", version = "0.6.1" }
search_index = { path = "../search_index" }
repo_url = { path = "../repo_url" }
......@@ -27,11 +25,15 @@ kitchen_sink = { path = "../kitchen_sink", version = "0.8" }
front_end = { path = "../front_end", version = "0.3.4" }
urlencoding = "1.0.0"
failure = "0.1.5"
tokio = "0.1.11"
tokio-timer = "0.2.10"
tokio = { version = "0.2.11", features = ["time"] }
categories = { path = "../categories" }
rayon = "1.3.0"
arc-swap = "0.4.4"
signal-hook = "0.1.12"
locale = "0.2.2"
cap = "0.1"
actix-rt = "1.0.0"
futures = "0.3.1"
actix-files = "0.2.1"
actix-threadpool = "0.3.1"
either = "1.5.3"
This diff is collapsed.
use futures::sink::{Sink, Wait};
use futures::sync::mpsc;
use futures::sink::SinkExt;
use futures::channel::mpsc;
use futures::Stream;
use std::io;
use actix_web::web::Bytes;
pub struct Writer<T, E>(Wait<mpsc::Sender<Result<T, E>>>);
pub struct Writer<T: 'static, E: 'static> {
sender: mpsc::Sender<Result<T, E>>,
rt: tokio::runtime::Runtime,
}
impl<T, E> Writer<T, E> {
pub fn fail(&mut self, error: E) {
let _ = self.0.send(Err(error));
let _ = self.sender.send(Err(error));
}
}
impl<T, E> io::Write for Writer<T, E>
impl<E: 'static> io::Write for Writer<Bytes, E>
where
T: for<'a> From<&'a [u8]> + Send + Sync + 'static,
E: Send + Sync + 'static,
{
fn write(&mut self, d: &[u8]) -> io::Result<usize> {
let len = d.len();
self.0
.send(Ok(d.into()))
.map(|()| len)
.map_err(|e| io::Error::new(io::ErrorKind::BrokenPipe, e))
let data = Bytes::copy_from_slice(d);
self.rt.block_on(self.sender.send(Ok(data)))
.map_err(|e| io::Error::new(io::ErrorKind::BrokenPipe, e))?;
Ok(len)
}
fn write_all(&mut self, d: &[u8]) -> io::Result<()> {
......@@ -29,15 +32,19 @@ where
}
fn flush(&mut self) -> io::Result<()> {
self.0
.flush()
.map_err(|e| io::Error::new(io::ErrorKind::BrokenPipe, e))
self.rt.block_on(self.sender
.flush())
.map_err(|e| io::Error::new(io::ErrorKind::BrokenPipe, e))?;
Ok(())
}
}
pub fn writer<T, E>() -> (Writer<T, E>, impl Stream<Item = T, Error = E>) {
pub fn writer<T, E: std::fmt::Debug>() -> (Writer<T, E>, impl Stream<Item = Result<T, E>>) {
let rt = tokio::runtime::Runtime::new().unwrap();
let (tx, rx) = mpsc::channel(3);
let w = Writer(tx.wait());
let r = rx.then(|r| r.unwrap());
(w, r)
let w = Writer {
sender: tx,
rt,
};
(w, rx)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment