diff options
Diffstat (limited to 'src/usecase')
| -rw-r--r-- | src/usecase/bootstrap.rs | 19 | ||||
| -rw-r--r-- | src/usecase/builds.rs | 6 | ||||
| -rw-r--r-- | src/usecase/detect.rs | 8 | ||||
| -rw-r--r-- | src/usecase/mod.rs | 21 | ||||
| -rw-r--r-- | src/usecase/reviews.rs | 29 | ||||
| -rw-r--r-- | src/usecase/subscriptions.rs | 6 |
6 files changed, 22 insertions, 67 deletions
diff --git a/src/usecase/bootstrap.rs b/src/usecase/bootstrap.rs index 6793076..a4e64d2 100644 --- a/src/usecase/bootstrap.rs +++ b/src/usecase/bootstrap.rs @@ -1,5 +1,4 @@ -//! Bringing a repository up, which every command does and every front end -//! used to write out for itself. +//! Bringing a repository up, which every command does. use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -10,17 +9,13 @@ use crate::error::Result; use crate::pipeline; /// Directories exist, the schema is current, and the repo row is present. -/// -/// Four calls in an order that matters — migrate before open, `ensure_repo` -/// before anything reads `repo_id` — which is precisely the kind of sequence -/// that quietly rots when it is copied. +/// Order matters: migrate before open, `ensure_repo` before anything reads +/// `repo_id`. pub fn open(cfg: &Config) -> Result<Db> { open_and_ensure(cfg).map(|(db, _)| db) } -/// `open`, plus the id of the row named by `cfg.repo_name` — which is what -/// `init` prints, and is not necessarily the lowest repo id if a root ever -/// holds more than one repo. +/// `open`, plus the id of the row named by `cfg.repo_name`. fn open_and_ensure(cfg: &Config) -> Result<(Db, i64)> { cfg.ensure_dirs()?; db::migrate(&cfg.db_path())?; @@ -44,10 +39,8 @@ pub fn init(cfg: &Config) -> Result<i64> { /// Everything `serve` does before control passes to the UI: bring the /// repository up, finish anything a previous run left half-published, and start -/// the two background loops. -/// -/// The HTTP server is deliberately not started here. This module sits below the -/// UI and must not be able to name it. +/// the two background loops. This module sits below the UI, so it cannot start +/// the HTTP server. pub fn serve(cfg: &Config) -> Result<Db> { let db = open(cfg)?; let _ = pipeline::publish::reconcile(cfg, &db); diff --git a/src/usecase/builds.rs b/src/usecase/builds.rs index 265e6cb..152959f 100644 --- a/src/usecase/builds.rs +++ b/src/usecase/builds.rs @@ -22,11 +22,7 @@ pub fn cancel(db: &Db, build_id: &str) -> Result<()> { builds::request_cancel(db, build_id) } -/// Retry a failed build, and record that someone asked. -/// -/// The audit row is part of the workflow rather than the caller's homework: a -/// retry changes what a build means, and a retry nobody asked for is exactly -/// what the audit trail is there to rule out. +/// Retry a failed build, and audit that someone asked. pub fn retry(db: &Db, actor: &str, build_id: &str) -> Result<()> { builds::retry(db, build_id)?; db::audit(&db.writer, actor, actor, "build.retry", "build", build_id, serde_json::json!({})) diff --git a/src/usecase/detect.rs b/src/usecase/detect.rs index 67cc83c..42f98d9 100644 --- a/src/usecase/detect.rs +++ b/src/usecase/detect.rs @@ -5,12 +5,8 @@ use crate::db::{self, Db, SubscriptionState}; use crate::error::Result; use crate::watch::detect::{self, Outcome}; -/// One pkgbase's detection result. -/// -/// Per-item failures are returned rather than raised: a sweep over every -/// subscription should not stop at the first pkgbase whose mirror is -/// unreachable, and the caller decides whether a failure is a line on stderr -/// or a row in a table. +/// One pkgbase's detection result. Per-item failures are returned, not raised, +/// so a sweep does not stop at the first unreachable mirror. pub struct Checked { pub pkgbase: String, pub outcome: Result<Outcome>, diff --git a/src/usecase/mod.rs b/src/usecase/mod.rs index 288d71d..25f745c 100644 --- a/src/usecase/mod.rs +++ b/src/usecase/mod.rs @@ -1,21 +1,6 @@ -//! The workflows themselves — the thing between a front end and the modules. -//! -//! Before this module existed, a workflow had one implementation per front end. -//! `main` opened the repository inline before its command match; `serve` opened -//! it again; the web routes wrote subscriptions and retried builds with their -//! own `db::` calls, so the CLI and the UI could drift and nothing would notice -//! until a reviewer saw one behaviour in the browser and another in the -//! terminal. -//! -//! A function here is a workflow only if more than one step has to happen in a -//! particular order. `subscribe` is a workflow because the repo row has to be -//! resolved first and a first detection may have to follow. `candidate_by_id` -//! is not, and stays where it is. -//! -//! Nothing in here formats output or knows a terminal, a form or a status code -//! exists. Results carry enough structure for each front end to say the same -//! facts in its own voice — which is why `Approved` reports the queueing -//! outcome rather than deciding whether a failed enqueue is fatal. +//! The workflows between a front end and the modules: a function belongs here +//! only when more than one step has to happen in a particular order. Nothing in +//! here formats output or knows a terminal, a form or a status code exists. mod bootstrap; mod builds; diff --git a/src/usecase/reviews.rs b/src/usecase/reviews.rs index 8cbb534..31aa859 100644 --- a/src/usecase/reviews.rs +++ b/src/usecase/reviews.rs @@ -14,11 +14,8 @@ pub struct Prepared { } /// Render the current diff and store its digest, so the approval that follows -/// can be checked against exactly what was shown rather than whatever the tree -/// looked like a moment later. -/// -/// `Ok(None)` means there is no such candidate; each front end says so in its -/// own words. +/// is checked against what was actually shown. `Ok(None)` means no such +/// candidate. pub fn prepare_review(cfg: &Config, db: &Db, candidate_id: i64) -> Result<Option<Prepared>> { let Some(c) = candidates::candidate_by_id(db, candidate_id)? else { return Ok(None); @@ -28,10 +25,8 @@ pub fn prepare_review(cfg: &Config, db: &Db, candidate_id: i64) -> Result<Option Ok(Some(Prepared { candidate: c, text, digest })) } -/// `prepare_review`, plus recording that a human actually looked at it. -/// -/// The review queue uses "viewed" to stop surfacing candidates nobody is -/// reading, so looking and approving are separate facts. +/// `prepare_review`, plus recording that a human looked at it — looking and +/// approving are separate facts. pub fn view_review(cfg: &Config, db: &Db, candidate_id: i64) -> Result<Option<Prepared>> { let Some(p) = prepare_review(cfg, db, candidate_id)? else { return Ok(None); @@ -43,10 +38,7 @@ pub fn view_review(cfg: &Config, db: &Db, candidate_id: i64) -> Result<Option<Pr /// An approval that was recorded, and whether a build came out of it. pub struct Approved { pub approval: ap::Approval, - /// Queuing is fatal in the CLI — an approved candidate with no build is a - /// silent stall — and a soft failure in the UI, which has already committed - /// the decision and can retry from the package page. So the workflow - /// reports it rather than choosing for both. + /// Fatal in the CLI, soft in the UI: reported, not decided for both. pub queued: Result<String>, } @@ -56,11 +48,8 @@ pub enum Approval { Refused(ap::Stale), } -/// Record an approval and queue the build it authorises. -/// -/// These are one workflow because an approval that never queues is the bug the -/// whole review queue exists to prevent, and both front ends had to remember to -/// pair them. +/// Record an approval and queue the build it authorises; one workflow, so an +/// approval can never fail to queue. pub fn approve( cfg: &Config, db: &Db, @@ -92,8 +81,8 @@ pub enum Decision { } /// Apply one decision to many candidates, queueing a build for each that -/// passed. Items that were refused — high risk without a confirmation, say — -/// come back with the reason rather than aborting the batch. +/// passed. A refused item comes back with its reason rather than aborting the +/// batch. pub fn bulk( cfg: &Config, db: &Db, diff --git a/src/usecase/subscriptions.rs b/src/usecase/subscriptions.rs index c504cfe..a37e650 100644 --- a/src/usecase/subscriptions.rs +++ b/src/usecase/subscriptions.rs @@ -9,11 +9,7 @@ pub struct Subscribe { pub url: String, } -/// Start watching a pkgbase. -/// -/// The repo row has to be resolved first, which is the step every front end -/// previously open-coded — and the web layer got it wrong, falling back to repo -/// id 1 rather than saying the repository was not initialised. +/// Start watching a pkgbase, resolving the repo row first. pub fn subscribe(db: &Db, pkgbase: &str, url: Option<String>) -> Result<Subscribe> { let rid = db::repo_id(db)?; let url = url.unwrap_or_else(|| format!("https://aur.archlinux.org/{pkgbase}.git")); |
