diff options
| author | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
| commit | 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch) | |
| tree | 7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /src/db/builds/mod.rs | |
| parent | 9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff) | |
| download | aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.tar.gz aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.zip | |
rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off
rustfmt.toml fixes the shape the tree is written in (120 columns, small
items kept on one line) and one canonical pass makes it the truth.
[lints.clippy] names the idiom lints worth enforcing and leaves out the
two that would add doc-comment boilerplate rather than remove it. The
tree pays them off here: write!/writeln! instead of push_str(&format!()),
let-else instead of match-on-Option, borrows where a thread entry point
only reads what it owns, no `&self` on a Copy state and no `self` nobody
reads.
ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and
value are now emitted by the same call instead of three.
Diffstat (limited to 'src/db/builds/mod.rs')
| -rw-r--r-- | src/db/builds/mod.rs | 58 |
1 files changed, 18 insertions, 40 deletions
diff --git a/src/db/builds/mod.rs b/src/db/builds/mod.rs index 83566ad..e31543e 100644 --- a/src/db/builds/mod.rs +++ b/src/db/builds/mod.rs @@ -78,12 +78,7 @@ pub fn enqueue( pub fn get(db: &Db, id: &str) -> Result<Option<BuildRow>> { let id = id.to_string(); db.read(move |c| { - Ok(c.query_row( - &format!("SELECT {BUILD_COLS} FROM build WHERE id=?1"), - params![id], - row_to_build, - ) - .optional()?) + Ok(c.query_row(&format!("SELECT {BUILD_COLS} FROM build WHERE id=?1"), params![id], row_to_build).optional()?) }) } @@ -98,7 +93,9 @@ pub fn list(db: &Db, states: &[BuildState], limit: i64) -> Result<Vec<BuildRow>> ); let mut stmt = c.prepare(&sql)?; let rows = stmt.query_map( - rusqlite::params_from_iter(states.iter().chain(std::iter::once(&limit.to_string())).map(|s| s as &dyn rusqlite::ToSql)), + rusqlite::params_from_iter( + states.iter().chain(std::iter::once(&limit.to_string())).map(|s| s as &dyn rusqlite::ToSql), + ), row_to_build, )?; let mut out = Vec::new(); @@ -111,9 +108,8 @@ pub fn list(db: &Db, states: &[BuildState], limit: i64) -> Result<Vec<BuildRow>> pub fn queued(db: &Db, limit: i64) -> Result<Vec<String>> { db.read(|c| { - let mut stmt = c.prepare( - "SELECT id FROM build WHERE state='queued' ORDER BY priority DESC, created_at LIMIT ?1", - )?; + let mut stmt = + c.prepare("SELECT id FROM build WHERE state='queued' ORDER BY priority DESC, created_at LIMIT ?1")?; let rows = stmt.query_map(params![limit], |r| r.get::<_, String>(0))?; let mut out = Vec::new(); for r in rows { @@ -150,10 +146,7 @@ pub fn extend_lease(db: &Db, id: &str, lease_secs: i64) -> Result<()> { let id = id.to_string(); let exp = time::secs_ahead(lease_secs); db.writer.tx(move |tx| { - tx.execute( - "UPDATE build SET lease_expires_at=?1 WHERE id=?2", - params![exp, id], - )?; + tx.execute("UPDATE build SET lease_expires_at=?1 WHERE id=?2", params![exp, id])?; Ok(()) }) } @@ -185,12 +178,7 @@ pub fn reap_expired(db: &Db) -> Result<usize> { }) } -fn transition_in_tx( - tx: &mut rusqlite::Transaction<'_>, - id: &str, - to: BuildState, - error: Option<&str>, -) -> Result<()> { +fn transition_in_tx(tx: &mut rusqlite::Transaction<'_>, id: &str, to: BuildState, error: Option<&str>) -> Result<()> { let froms = BuildState::predecessors(to); let placeholders = froms.iter().map(|_| "?").collect::<Vec<_>>().join(","); let sql = format!( @@ -205,9 +193,8 @@ fn transition_in_tx( } let n = tx.execute(&sql, rusqlite::params_from_iter(args))?; if n == 0 { - let was: Option<String> = tx - .query_row("SELECT state FROM build WHERE id=?1", params![id], |r| r.get(0)) - .optional()?; + let was: Option<String> = + tx.query_row("SELECT state FROM build WHERE id=?1", params![id], |r| r.get(0)).optional()?; return Err(match was { Some(s) => Error::invalid(format!("illegal build transition {s} → {to} for build {id}")), None => Error::invalid(format!("no build {id} to move to {to}")), @@ -218,9 +205,8 @@ fn transition_in_tx( pub fn set_state(db: &Db, id: &str, to: BuildState, error: Option<&str>) -> Result<()> { let id = id.to_string(); - let error = error.map(|e| e.to_string()); - db.writer - .tx(move |tx| transition_in_tx(tx, &id, to, error.as_deref())) + let error = error.map(std::string::ToString::to_string); + db.writer.tx(move |tx| transition_in_tx(tx, &id, to, error.as_deref())) } pub fn block_on(db: &Db, id: &str, blocked_on: &[String]) -> Result<()> { @@ -245,9 +231,7 @@ pub fn requeue_blocked(db: &Db) -> Result<usize> { }; let in_index: std::collections::HashSet<String> = { let mut stmt = tx.prepare("SELECT name FROM package WHERE state='in_index'")?; - let names = stmt - .query_map([], |r| r.get::<_, String>(0))? - .collect::<rusqlite::Result<Vec<String>>>()?; + let names = stmt.query_map([], |r| r.get::<_, String>(0))?.collect::<rusqlite::Result<Vec<String>>>()?; names.into_iter().collect() }; let mut n = 0; @@ -277,23 +261,17 @@ pub fn request_cancel(db: &Db, id: &str) -> Result<()> { pub fn cancel_requested(db: &Db, id: &str) -> Result<bool> { let id = id.to_string(); db.read(move |c| { - Ok(c.query_row("SELECT cancel_requested FROM build WHERE id=?1", params![id], |r| { - Ok(r.get::<_, i64>(0)? != 0) - }) - .optional()? - .unwrap_or(false)) + Ok(c.query_row("SELECT cancel_requested FROM build WHERE id=?1", params![id], |r| Ok(r.get::<_, i64>(0)? != 0)) + .optional()? + .unwrap_or(false)) }) } - // The step machine is its own concern: same build, one row per step, its own // legal moves. mod steps; - pub use steps::{ - begin_step, blocked_builds, cancel_superseded, claim_batch, - finish_step, in_flight, queue_depth, requeue_transient, - retry, set_blocked_on, set_release_in, set_world, - step_status, steps, + begin_step, blocked_builds, cancel_superseded, claim_batch, finish_step, in_flight, queue_depth, requeue_transient, + retry, set_blocked_on, set_release_in, set_world, step_status, steps, }; |
