Skip to content

Commit 5360c51

Browse files
add cratesfyi queue add command
1 parent 19e31e3 commit 5360c51

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

src/bin/cratesfyi.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use std::path::PathBuf;
1212

1313
use clap::{Arg, App, SubCommand};
1414
use cratesfyi::{DocBuilder, DocBuilderOptions, db};
15-
use cratesfyi::utils::build_doc;
15+
use cratesfyi::utils::{build_doc, add_crate_to_queue};
1616
use cratesfyi::start_web_server;
17-
use cratesfyi::db::add_path_into_database;
17+
use cratesfyi::db::{add_path_into_database, connect_db};
1818

1919

2020
pub fn main() {
@@ -130,6 +130,23 @@ pub fn main() {
130130
chart")
131131
.subcommand(SubCommand::with_name("update-search-index"))
132132
.about("Updates search index"))
133+
.subcommand(SubCommand::with_name("queue")
134+
.about("Interactions with the build queue")
135+
.subcommand(SubCommand::with_name("add")
136+
.about("Add a crate to the build queue")
137+
.arg(Arg::with_name("CRATE_NAME")
138+
.index(1)
139+
.required(true)
140+
.help("Name of crate to build"))
141+
.arg(Arg::with_name("CRATE_VERSION")
142+
.index(2)
143+
.required(true)
144+
.help("Version of crate to build"))
145+
.arg(Arg::with_name("BUILD_PRIORITY")
146+
.short("p")
147+
.long("priority")
148+
.help("Priority of build (default: 5) (new crate builds get priority 0)")
149+
.takes_value(true))))
133150
.get_matches();
134151

135152

@@ -227,6 +244,17 @@ pub fn main() {
227244
start_web_server(Some(matches.value_of("SOCKET_ADDR").unwrap_or("0.0.0.0:3000")));
228245
} else if let Some(_) = matches.subcommand_matches("daemon") {
229246
cratesfyi::utils::start_daemon();
247+
} else if let Some(matches) = matches.subcommand_matches("queue") {
248+
if let Some(matches) = matches.subcommand_matches("add") {
249+
let priority = matches.value_of("BUILD_PRIORITY").unwrap_or("5");
250+
let priority: i32 = priority.parse().expect("--priority was not a number");
251+
let conn = connect_db().expect("Could not connect to database");
252+
253+
add_crate_to_queue(&conn,
254+
matches.value_of("CRATE_NAME").unwrap(),
255+
matches.value_of("CRATE_VERSION").unwrap(),
256+
priority).expect("Could not add crate to queue");
257+
}
230258
} else {
231259
println!("{}", matches.usage());
232260
}

src/docbuilder/queue.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::DocBuilder;
55
use db::connect_db;
66
use error::Result;
77
use crates_index_diff::{ChangeKind, Index};
8+
use utils::add_crate_to_queue;
89

910

1011
impl DocBuilder {
@@ -20,9 +21,7 @@ impl DocBuilder {
2021
changes.reverse();
2122

2223
for krate in changes.iter().filter(|k| k.kind != ChangeKind::Yanked) {
23-
conn.execute("INSERT INTO queue (name, version, priority) VALUES ($1, $2, 0)",
24-
&[&krate.name, &krate.version])
25-
.ok();
24+
add_crate_to_queue(&conn, &krate.name, &krate.version, 0).ok();
2625
debug!("{}-{} added into build queue", krate.name, krate.version);
2726
add_count += 1;
2827
}

src/utils/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub use self::release_activity_updater::update_release_activity;
88
pub use self::daemon::start_daemon;
99
pub use self::rustc_version::{parse_rustc_version, get_current_versions, command_result};
1010
pub use self::html::extract_head_and_body;
11+
pub use self::queue::add_crate_to_queue;
1112

1213
mod github_updater;
1314
mod build_doc;
@@ -17,3 +18,4 @@ mod daemon;
1718
mod pubsubhubbub;
1819
mod rustc_version;
1920
mod html;
21+
mod queue;

src/utils/queue.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Utilities for interacting with the build queue
2+
3+
use postgres::Connection;
4+
use error::Result;
5+
6+
pub fn add_crate_to_queue(conn: &Connection, name: &str, version: &str, priority: i32) -> Result<()> {
7+
try!(conn.execute("INSERT INTO queue (name, version, priority) VALUES ($1, $2, $3)",
8+
&[&name, &version, &priority]));
9+
Ok(())
10+
}

0 commit comments

Comments
 (0)