mirror of
https://github.com/Noratrieb/cargo-bisect-rustc-service.git
synced 2026-01-14 16:25:01 +01:00
works?
This commit is contained in:
parent
e78b5becde
commit
b36cab3491
6 changed files with 248 additions and 63 deletions
37
Cargo.lock
generated
37
Cargo.lock
generated
|
|
@ -479,6 +479,15 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "matchers"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
|
||||||
|
dependencies = [
|
||||||
|
"regex-automata",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matchit"
|
name = "matchit"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
|
@ -699,6 +708,30 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
|
||||||
|
dependencies = [
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.1.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||||
|
dependencies = [
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.6.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "remove_dir_all"
|
name = "remove_dir_all"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
|
|
@ -1005,9 +1038,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b"
|
checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term",
|
"ansi_term",
|
||||||
|
"matchers",
|
||||||
|
"once_cell",
|
||||||
|
"regex",
|
||||||
"sharded-slab",
|
"sharded-slab",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
|
"tracing",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,5 @@ serde = { version = "1.0.145", features = ["derive"] }
|
||||||
tempdir = "0.3.7"
|
tempdir = "0.3.7"
|
||||||
tokio = { version = "1.21.2", features = ["full"] }
|
tokio = { version = "1.21.2", features = ["full"] }
|
||||||
tracing = "0.1.36"
|
tracing = "0.1.36"
|
||||||
tracing-subscriber = "0.3.15"
|
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
|
||||||
uuid = { version = "1.1.2", features = ["serde", "v4"] }
|
uuid = { version = "1.1.2", features = ["serde", "v4"] }
|
||||||
|
|
|
||||||
88
index.html
88
index.html
|
|
@ -7,6 +7,10 @@
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#result {
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
.hidden {
|
.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
@ -30,55 +34,89 @@
|
||||||
cols="80"
|
cols="80"
|
||||||
placeholder="// Rust code goes here..."
|
placeholder="// Rust code goes here..."
|
||||||
>
|
>
|
||||||
fn uwu() {}
|
fn main() {}</textarea
|
||||||
</textarea>
|
>
|
||||||
|
<br />
|
||||||
|
<label for="start">Start</label>
|
||||||
|
<input id="start" value="2022-01-01" />
|
||||||
|
<label for="end">End (optional)</label>
|
||||||
|
<input id="end" />
|
||||||
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<button class="bisect-btn" onclick="bisect()">Bisect!</button>
|
<button class="bisect-btn" onclick="bisect()">Bisect!</button>
|
||||||
|
|
||||||
<div id="status" class="hidden" />
|
<br />
|
||||||
<div id="result" class="hidden" />
|
<br />
|
||||||
|
<div id="status" class="hidden"></div>
|
||||||
|
<br />
|
||||||
|
<textarea
|
||||||
|
id="result"
|
||||||
|
class="hidden"
|
||||||
|
cols="80"
|
||||||
|
rows="20"
|
||||||
|
readonly
|
||||||
|
></textarea>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
const BASE_URL = `${document.location}`;
|
||||||
|
const code = document.getElementById("code");
|
||||||
|
const status = document.getElementById("status");
|
||||||
|
const result = document.getElementById("result");
|
||||||
|
const start = document.getElementById("start");
|
||||||
|
const end = document.getElementById("end");
|
||||||
|
|
||||||
let bisecting = false;
|
let bisecting = false;
|
||||||
|
|
||||||
async function bisect() {
|
async function bisect() {
|
||||||
if (bisecting) {
|
if (bisecting) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!start.value.trim()) {
|
||||||
|
alert("Must provide a start");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bisecting = true;
|
bisecting = true;
|
||||||
const code = document.getElementById("code");
|
|
||||||
const status = document.getElementById("status");
|
|
||||||
const result = document.getElementById("result");
|
|
||||||
|
|
||||||
status.classList.remove("hidden");
|
status.classList.remove("hidden");
|
||||||
|
result.classList.add("hidden");
|
||||||
status.innerText = "Sending request...";
|
status.innerText = "Sending request...";
|
||||||
|
|
||||||
const fetched = await fetch(
|
const params = new URLSearchParams();
|
||||||
"https://bisect-rustc.nilstrieb.dev/bisect",
|
params.append("start", start.value.trim());
|
||||||
{
|
if (end.value.trim()) {
|
||||||
method: "POST",
|
params.append("end", end.value.trim());
|
||||||
body: code.value,
|
}
|
||||||
}
|
|
||||||
);
|
const fetched = await fetch(`${BASE_URL}bisect?${params}`, {
|
||||||
const { id } = await fetched.json();
|
method: "POST",
|
||||||
|
body: code.value,
|
||||||
|
});
|
||||||
|
const { job_id } = await fetched.json();
|
||||||
|
|
||||||
async function tryFetch() {
|
async function tryFetch() {
|
||||||
const fetched = await fetch(
|
const fetched = await fetch(`${BASE_URL}bisect/${job_id}`);
|
||||||
`https://bisect-rustc.nilstrieb.dev/bisect/${id}`
|
const response = await fetched.json();
|
||||||
);
|
|
||||||
const { done, output, time } = await fetched.json();
|
|
||||||
|
|
||||||
if (done) {
|
if (response.status.status !== "InProgress") {
|
||||||
bisecting = false;
|
bisecting = false;
|
||||||
result.innerText = output;
|
console.log(response.status.output);
|
||||||
status.innerText = `Bisected job ${id} successfully in ${time}ms`;
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(tryFetch, 3000);
|
status.classList.add("hidden");
|
||||||
|
result.classList.remove("hidden");
|
||||||
|
|
||||||
|
result.value = response.status.output;
|
||||||
|
status.innerHTML = `Bisected job ${job_id}`;
|
||||||
|
} else {
|
||||||
|
console.log("Waiting for bisection", response.status.status);
|
||||||
|
setTimeout(tryFetch, 3000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tryFetch();
|
tryFetch();
|
||||||
|
|
||||||
status.innerHTML = `Waiting for bisection, job id=${id}`;
|
status.innerHTML = `Waiting for result, job id=${job_id}`;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,21 @@
|
||||||
|
use std::process::Output;
|
||||||
use std::{fs, process::Command, sync::mpsc};
|
use std::{fs, process::Command, sync::mpsc};
|
||||||
|
|
||||||
use color_eyre::eyre::Context;
|
use color_eyre::eyre::{Context, ContextCompat};
|
||||||
|
use color_eyre::Result;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::Options;
|
use crate::{db, Options};
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(tag = "status")]
|
||||||
pub enum BisectStatus {
|
pub enum BisectStatus {
|
||||||
InProgress,
|
InProgress,
|
||||||
Error(String),
|
Error { output: String },
|
||||||
Success(String),
|
Success { output: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
|
@ -29,15 +32,15 @@ pub struct Job {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum JobState {
|
enum JobState {
|
||||||
Failed(String),
|
Failed,
|
||||||
Success(String),
|
Success,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JobState {
|
impl JobState {
|
||||||
fn status(&self) -> &'static str {
|
fn status(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Failed(_) => "error",
|
Self::Failed => "error",
|
||||||
Self::Success(_) => "success",
|
Self::Success => "success",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -66,27 +69,69 @@ pub fn bisect_worker(jobs: mpsc::Receiver<Job>, conn: Connection) {
|
||||||
|
|
||||||
info!(id = %job.id, "Starting bisection job");
|
info!(id = %job.id, "Starting bisection job");
|
||||||
|
|
||||||
bisect_job(job);
|
let mut bisect = Bisection {
|
||||||
|
id: job.id,
|
||||||
|
code: job.code.clone(),
|
||||||
|
status: BisectStatus::InProgress,
|
||||||
|
};
|
||||||
|
|
||||||
|
match db::add_bisection(&conn, &bisect).wrap_err("insert bisection") {
|
||||||
|
Ok(()) => {
|
||||||
|
let status = match bisect_job(job) {
|
||||||
|
Ok(status) => status,
|
||||||
|
Err(err) => {
|
||||||
|
error!(?err, "error processing bisection");
|
||||||
|
BisectStatus::Error {
|
||||||
|
output: err.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bisect.status = status;
|
||||||
|
|
||||||
|
match db::update_bisection_status(&conn, &bisect) {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(err) => error!(?err, "error updating bisection"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => error!(?err, "error inserting bisection"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(job), fields(id = %job.id))]
|
#[tracing::instrument(skip(job), fields(id = %job.id))]
|
||||||
fn bisect_job(job: Job) {
|
fn bisect_job(job: Job) -> Result<BisectStatus> {
|
||||||
match run_bisect_for_file(job.code, job.options.start, job.options.end) {
|
let (output, state) = run_bisect_for_file(job.code, job.options.start, job.options.end)?;
|
||||||
Ok(state) => {
|
info!(state = %state.status(), "Bisection finished");
|
||||||
info!(state = %state.status(), "Bisection finished");
|
|
||||||
|
process_result(output, state).wrap_err("process result")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process_result(output: Output, state: JobState) -> Result<BisectStatus> {
|
||||||
|
let stderr =
|
||||||
|
String::from_utf8(output.stderr).wrap_err("cargo-bisect-rustc stderr utf8 validation")?;
|
||||||
|
|
||||||
|
match state {
|
||||||
|
JobState::Failed => {
|
||||||
|
let output = stderr.lines().rev().take(10).collect::<String>();
|
||||||
|
info!(?output, "output");
|
||||||
|
Ok(BisectStatus::Error { output })
|
||||||
}
|
}
|
||||||
Err(err) => {
|
JobState::Success => {
|
||||||
error!(?err, "Error during bisection");
|
let cutoff = stderr.rfind("searched nightlies:").wrap_err_with(|| {
|
||||||
|
format!("cannot find `searched nightlies:` in output. output:\n{stderr}")
|
||||||
|
})?;
|
||||||
|
let output = stderr[cutoff..].to_string();
|
||||||
|
Ok(BisectStatus::Success { output })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_bisect_for_file(
|
fn run_bisect_for_file(
|
||||||
input: String,
|
input: String,
|
||||||
start: Option<chrono::NaiveDate>,
|
start: chrono::NaiveDate,
|
||||||
end: Option<chrono::NaiveDate>,
|
end: Option<chrono::NaiveDate>,
|
||||||
) -> color_eyre::Result<JobState> {
|
) -> Result<(Output, JobState)> {
|
||||||
let temp_dir = tempdir::TempDir::new("bisect").wrap_err("creating tempdir")?;
|
let temp_dir = tempdir::TempDir::new("bisect").wrap_err("creating tempdir")?;
|
||||||
let mut cargo_new = Command::new("cargo");
|
let mut cargo_new = Command::new("cargo");
|
||||||
cargo_new
|
cargo_new
|
||||||
|
|
@ -111,9 +156,7 @@ fn run_bisect_for_file(
|
||||||
bisect.arg("--timeout").arg("30"); // don't hang
|
bisect.arg("--timeout").arg("30"); // don't hang
|
||||||
bisect.current_dir(&cargo_dir);
|
bisect.current_dir(&cargo_dir);
|
||||||
|
|
||||||
if let Some(start) = start {
|
bisect.arg("--start").arg(start.to_string());
|
||||||
bisect.arg("--start").arg(start.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(end) = end {
|
if let Some(end) = end {
|
||||||
bisect.arg("--end").arg(end.to_string());
|
bisect.arg("--end").arg(end.to_string());
|
||||||
|
|
@ -122,14 +165,8 @@ fn run_bisect_for_file(
|
||||||
let output = bisect.output().wrap_err("spawning cargo-bisect-rustc")?;
|
let output = bisect.output().wrap_err("spawning cargo-bisect-rustc")?;
|
||||||
|
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
Ok(JobState::Success(
|
Ok((output, JobState::Success))
|
||||||
String::from_utf8(output.stdout)
|
|
||||||
.wrap_err("cargo-bisect-rustc stdout utf8 validation")?,
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(JobState::Failed(
|
Ok((output, JobState::Failed))
|
||||||
String::from_utf8(output.stderr)
|
|
||||||
.wrap_err("cargo-bisect-rustc stderr utf8 validation")?,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
68
src/db.rs
68
src/db.rs
|
|
@ -1,6 +1,7 @@
|
||||||
use color_eyre::eyre::Context;
|
use color_eyre::eyre::Context;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::bisect::{BisectStatus, Bisection};
|
use crate::bisect::{BisectStatus, Bisection};
|
||||||
|
|
||||||
|
|
@ -21,13 +22,39 @@ pub fn setup(conn: &Connection) -> color_eyre::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_bisection(conn: &Connection) -> color_eyre::Result<()> {
|
fn status_to_sql(status: &BisectStatus) -> (u8, Option<&str>) {
|
||||||
Ok(())
|
match status {
|
||||||
|
BisectStatus::InProgress => (0, None),
|
||||||
|
BisectStatus::Error { output } => (1, Some(&output)),
|
||||||
|
BisectStatus::Success { output } => (2, Some(&output)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_bisection(conn: &Connection, bisect: &Bisection) -> color_eyre::Result<()> {
|
||||||
|
let (status, stdout_stderr) = status_to_sql(&bisect.status);
|
||||||
|
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO bisect (job_id, code, status, stdout_stderr) VALUES (?1, ?2, ?3, ?4)",
|
||||||
|
(bisect.id, &bisect.code, status, stdout_stderr),
|
||||||
|
)
|
||||||
|
.wrap_err("insert into database")
|
||||||
|
.map(drop)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_bisection_status(conn: &Connection, bisect: &Bisection) -> color_eyre::Result<()> {
|
||||||
|
let (status, stdout_stderr) = status_to_sql(&bisect.status);
|
||||||
|
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE bisect SET status = ?1, stdout_stderr = ?2 WHERE bisect.job_id = ?3",
|
||||||
|
(status, stdout_stderr, bisect.id),
|
||||||
|
)
|
||||||
|
.wrap_err("insert into database")
|
||||||
|
.map(drop)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_bisections(conn: &Connection) -> color_eyre::Result<Vec<Bisection>> {
|
pub fn get_bisections(conn: &Connection) -> color_eyre::Result<Vec<Bisection>> {
|
||||||
let mut select = conn
|
let mut select = conn
|
||||||
.prepare("SELECT job_id, code, status, stdout, stderr FROM bisect")
|
.prepare("SELECT job_id, code, status, stdout_stderr FROM bisect")
|
||||||
.wrap_err("preparing select")?;
|
.wrap_err("preparing select")?;
|
||||||
|
|
||||||
let iter = select
|
let iter = select
|
||||||
|
|
@ -37,8 +64,12 @@ pub fn get_bisections(conn: &Connection) -> color_eyre::Result<Vec<Bisection>> {
|
||||||
code: row.get(1)?,
|
code: row.get(1)?,
|
||||||
status: match row.get(2)? {
|
status: match row.get(2)? {
|
||||||
0 => BisectStatus::InProgress,
|
0 => BisectStatus::InProgress,
|
||||||
1 => BisectStatus::Error(row.get(3)?),
|
1 => BisectStatus::Error {
|
||||||
2 => BisectStatus::Success(row.get(3)?),
|
output: row.get(3)?,
|
||||||
|
},
|
||||||
|
2 => BisectStatus::Success {
|
||||||
|
output: row.get(3)?,
|
||||||
|
},
|
||||||
_ => return Err(rusqlite::Error::InvalidQuery), // actually not lol
|
_ => return Err(rusqlite::Error::InvalidQuery), // actually not lol
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -48,3 +79,30 @@ pub fn get_bisections(conn: &Connection) -> color_eyre::Result<Vec<Bisection>> {
|
||||||
iter.collect::<Result<Vec<_>, rusqlite::Error>>()
|
iter.collect::<Result<Vec<_>, rusqlite::Error>>()
|
||||||
.wrap_err("getting bisections from db")
|
.wrap_err("getting bisections from db")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_bisection(conn: &Connection, id: Uuid) -> color_eyre::Result<Option<Bisection>> {
|
||||||
|
let mut select = conn
|
||||||
|
.prepare("SELECT job_id, code, status, stdout_stderr FROM bisect WHERE job_id = ?1")
|
||||||
|
.wrap_err("preparing select")?;
|
||||||
|
|
||||||
|
let mut iter = select
|
||||||
|
.query_map([id], |row| {
|
||||||
|
Ok(Bisection {
|
||||||
|
id: row.get(0)?,
|
||||||
|
code: row.get(1)?,
|
||||||
|
status: match row.get(2)? {
|
||||||
|
0 => BisectStatus::InProgress,
|
||||||
|
1 => BisectStatus::Error {
|
||||||
|
output: row.get(3)?,
|
||||||
|
},
|
||||||
|
2 => BisectStatus::Success {
|
||||||
|
output: row.get(3)?,
|
||||||
|
},
|
||||||
|
_ => return Err(rusqlite::Error::InvalidQuery), // actually not lol
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.wrap_err("getting bisections from db query")?;
|
||||||
|
|
||||||
|
iter.next().transpose().wrap_err("getting bisection")
|
||||||
|
}
|
||||||
|
|
|
||||||
23
src/main.rs
23
src/main.rs
|
|
@ -6,7 +6,7 @@ mod db;
|
||||||
use std::sync::{mpsc, Arc, Mutex};
|
use std::sync::{mpsc, Arc, Mutex};
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::Query,
|
extract::{Path, Query},
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{Html, IntoResponse},
|
response::{Html, IntoResponse},
|
||||||
routing::{get, post, Router},
|
routing::{get, post, Router},
|
||||||
|
|
@ -18,6 +18,7 @@ use rusqlite::Connection;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::env;
|
use std::env;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
type SendChannel = Arc<Mutex<mpsc::Sender<Job>>>;
|
type SendChannel = Arc<Mutex<mpsc::Sender<Job>>>;
|
||||||
|
|
@ -27,7 +28,9 @@ type Conn = Arc<Mutex<Connection>>;
|
||||||
async fn main() -> color_eyre::Result<()> {
|
async fn main() -> color_eyre::Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
|
||||||
tracing_subscriber::fmt().init();
|
tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(EnvFilter::from_default_env())
|
||||||
|
.init();
|
||||||
|
|
||||||
let (job_queue_send, job_queue_recv) = mpsc::channel();
|
let (job_queue_send, job_queue_recv) = mpsc::channel();
|
||||||
|
|
||||||
|
|
@ -44,7 +47,7 @@ async fn main() -> color_eyre::Result<()> {
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(|| async { index_html() }))
|
.route("/", get(|| async { index_html() }))
|
||||||
// .route("/bisect/:id", get(get_bisection))
|
.route("/bisect/:id", get(get_bisection))
|
||||||
.route("/bisect", get(get_bisections))
|
.route("/bisect", get(get_bisections))
|
||||||
.route("/bisect", post(do_bisection))
|
.route("/bisect", post(do_bisection))
|
||||||
// this is really stupid and hacky
|
// this is really stupid and hacky
|
||||||
|
|
@ -65,6 +68,18 @@ fn index_html() -> impl IntoResponse {
|
||||||
Html(include_str!("../index.html"))
|
Html(include_str!("../index.html"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_bisection(
|
||||||
|
Extension(conn): Extension<Conn>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
db::get_bisection(&conn.lock().unwrap(), id)
|
||||||
|
.map(|bisections| Json(bisections))
|
||||||
|
.map_err(|err| {
|
||||||
|
error!(?err, "error getting bisections");
|
||||||
|
(StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_bisections(Extension(conn): Extension<Conn>) -> impl IntoResponse {
|
async fn get_bisections(Extension(conn): Extension<Conn>) -> impl IntoResponse {
|
||||||
db::get_bisections(&conn.lock().unwrap())
|
db::get_bisections(&conn.lock().unwrap())
|
||||||
.map(|bisections| Json(bisections))
|
.map(|bisections| Json(bisections))
|
||||||
|
|
@ -76,7 +91,7 @@ async fn get_bisections(Extension(conn): Extension<Conn>) -> impl IntoResponse {
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
start: Option<chrono::NaiveDate>,
|
start: chrono::NaiveDate,
|
||||||
end: Option<chrono::NaiveDate>,
|
end: Option<chrono::NaiveDate>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue