Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update swirl #1677

Merged
merged 2 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 62 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ dotenv = "0.11.0"
toml = "0.4"
diesel = { version = "1.4.0", features = ["postgres", "serde_json", "chrono", "r2d2"] }
diesel_full_text_search = "1.0.0"
swirl = { git = "https://github.com/sgrif/swirl.git", rev = "95d3a35bc39a7274335cad6d7cab64acd5eb3904" }
swirl = { git = "https://github.com/sgrif/swirl.git", rev = "de5d8bb" }
serde_json = "1.0.0"
serde_derive = "1.0.0"
serde = "1.0.0"
serde = { version = "1.0.0", features = ["derive"] }
chrono = { version = "0.4.0", features = ["serde"] }
comrak = { version = "0.4.0", default-features = false }
ammonia = "2.0.0"
Expand Down
14 changes: 6 additions & 8 deletions src/background_jobs.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
use std::panic::AssertUnwindSafe;
use std::sync::{Mutex, MutexGuard};
use swirl::{Builder, Runner};

use crate::db::{DieselPool, DieselPooledConn};
use crate::git::{AddCrate, Repository, Yank};
use crate::git::Repository;
use crate::util::errors::{CargoErrToStdErr, CargoResult};

impl<'a> swirl::DieselPool<'a> for DieselPool {
impl<'a> swirl::db::BorrowedConnection<'a> for DieselPool {
type Connection = DieselPooledConn<'a>;
}

impl swirl::db::DieselPool for DieselPool {
type Error = CargoErrToStdErr;

fn get(&'a self) -> Result<Self::Connection, Self::Error> {
fn get(&self) -> Result<swirl::db::DieselPooledConn<'_, Self>, Self::Error> {
self.get().map_err(CargoErrToStdErr)
}
}

pub fn job_runner(config: Builder<Environment, DieselPool>) -> Runner<Environment, DieselPool> {
config.register::<AddCrate>().register::<Yank>().build()
}

#[allow(missing_debug_implementations)]
pub struct Environment {
index: Mutex<Repository>,
Expand Down
6 changes: 4 additions & 2 deletions src/bin/background-worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ fn main() {

let environment = Environment::new(repository, credentials, db_pool.clone());

let builder = swirl::Runner::builder(db_pool, environment).thread_count(1);
let runner = job_runner(builder);
let runner = swirl::Runner::builder(db_pool, environment)
.thread_count(1)
.job_start_timeout(Duration::from_secs(10))
.build();

println!("Runner booted, running jobs");

Expand Down
3 changes: 0 additions & 3 deletions src/bin/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

#![deny(warnings)]

#[macro_use]
extern crate serde_derive;

mod on_call;

use cargo_registry::{db, util::CargoResult};
Expand Down
6 changes: 3 additions & 3 deletions src/bin/on_call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cargo_registry::util::{internal, CargoResult};

use reqwest::{header, StatusCode as Status};

#[derive(Serialize, Debug)]
#[derive(serde::Serialize, Debug)]
#[serde(rename_all = "snake_case", tag = "event_type")]
pub enum Event {
Trigger {
Expand Down Expand Up @@ -54,14 +54,14 @@ impl Event {
}
}

#[derive(Serialize, Debug)]
#[derive(serde::Serialize, Debug)]
struct FullEvent {
service_key: String,
#[serde(flatten)]
event: Event,
}

#[derive(Deserialize, Debug)]
#[derive(serde::Deserialize, Debug)]
struct InvalidEvent {
message: String,
errors: Vec<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/render-readmes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#![deny(warnings)]

#[macro_use]
extern crate serde_derive;
extern crate serde;

use cargo_registry::{
db,
Expand Down
3 changes: 0 additions & 3 deletions src/bin/test-pagerduty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

#![deny(warnings)]

#[macro_use]
extern crate serde_derive;

mod on_call;

use std::env::args;
Expand Down
28 changes: 15 additions & 13 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
//! Functionality related to publishing a new crate or version of a crate.

use hex::ToHex;
use std::collections::HashMap;
use std::sync::Arc;

use hex::ToHex;

use crate::git;
use crate::render;
use crate::util::{internal, ChainError, Maximums};
use crate::util::{read_fill, read_le_u32};
use swirl::Job;

use crate::controllers::prelude::*;
use crate::git;
use crate::models::dependency;
use crate::models::{Badge, Category, Keyword, NewCrate, NewVersion, Rights, User};
use crate::render;
use crate::util::{internal, CargoError, ChainError, Maximums};
use crate::util::{read_fill, read_le_u32};
use crate::views::{EncodableCrateUpload, GoodCrate, PublishWarnings};

/// Handles the `PUT /crates/new` route.
Expand Down Expand Up @@ -196,12 +195,15 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
yanked: Some(false),
links,
};
git::add_crate(&conn, git_crate).chain_error(|| {
internal(&format_args!(
"could not add crate `{}` to the git repo",
name
))
})?;
git::add_crate(git_crate)
.enqueue(&conn)
.map_err(|e| CargoError::from_std_error(e))
.chain_error(|| {
internal(&format_args!(
"could not add crate `{}` to the git repo",
name
))
})?;

// Now that we've come this far, we're committed!
crate_bomb.path = None;
Expand Down
12 changes: 7 additions & 5 deletions src/controllers/version/yank.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Endpoints for yanking and unyanking specific versions of crates

use crate::controllers::prelude::*;
use swirl::Job;

use super::version_and_crate;
use crate::controllers::prelude::*;
use crate::git;

use crate::models::Rights;

use super::version_and_crate;
use crate::util::CargoError;

/// Handles the `DELETE /crates/:crate_id/:version/yank` route.
/// This does not delete a crate version, it makes the crate
Expand Down Expand Up @@ -36,7 +36,9 @@ fn modify_yank(req: &mut dyn Request, yanked: bool) -> CargoResult<Response> {
return Err(human("must already be an owner to yank or unyank"));
}

git::yank(&conn, krate.name, version, yanked)?;
git::yank(krate.name, version, yanked)
.enqueue(&conn)
.map_err(|e| CargoError::from_std_error(e))?;

#[derive(Serialize)]
struct R {
Expand Down
Loading