pub async fn drive(
pool: &SqlitePool,
prepared: PreparedTune,
ctrl_c: &mut CtrlC,
) -> Result<TuneOutcome>Expand description
Runs an already-prepared tune to completion – the print-free counterpart to
[run_with_ctrl_c], for a caller with no terminal to print a summary to and no stdin to
prompt on (bhtune-server’s background tune task, tokio::spawned after its
POST /api/runs handler has already returned prepared.run_id() to the HTTP client).
Calls the exact same [execute] this module’s CLI path calls, with the exact same
arguments, so the actual tuning behavior – quality checks, restore-on-abort, write-back
rollback, all of it – is identical between the CLI and an HTTP-started run; only the
reporting differs. On success, returns the same coarse TuneOutcome
run_with_ctrl_c’s printed summary would have shown, computed via the same
tune_outcome_for_run mapping, and logs it exactly as run_with_ctrl_c does. On
failure, records the same tune_runs.fail row run_with_ctrl_c would have.
A caller that wants the same rich per-response-level detail print_summary shows on the
CLI should instead read the run back from the database once this resolves (over HTTP,
GET /api/runs/{id}) – execute’s own DB writes (tune_results/tune_writes) are the
authoritative record of everything print_summary would have printed, so there is
nothing this function needs to hand back beyond the coarse outcome.
prepared.args.output should be OutputFormat::Json for every caller of this
function, even though nothing here actually prints: [maybe_write_back] (called from
inside [execute]) skips its interactive stdin prompt only when output == OutputFormat::Json (see that function’s doc comment) – a caller with no stdin to read
from at all must never risk hitting that prompt. Accordingly, this function passes
[execute] a std::io::empty() reader rather than real stdin – besides there being
no human to prompt, std::io::Empty is Send (unlike a real std::io::StdinLock),
which is what allows the future returned by a call to this function to be
tokio::spawned at all (see execute’s own doc comment).