Skip to main content

dispatch

Function dispatch 

Source
pub async fn dispatch(app: App) -> Result<(), Box<dyn Error + Send + Sync>>
Expand description

Parse argv and run the requested management subcommand against the passed-in App. The user binary’s main.rs calls this after wiring its App — see the module-level docs for the pattern.

§Build the app with [AppBuilder::build_deferred]

let app = App::builder()
    .settings(settings)
    .database("default", pool)
    .plugin(AuthPlugin::default())
    .build_deferred()?;          // wire, but don't fire `on_ready` yet

umbral_cli::dispatch(app).await  // fires it iff argv warrants it

on_ready is where plugins seed content, backfill rows, and create the standard permissions — all of which need a migrated schema. dispatch is the first place that knows what argv asked for, so it is the only place that can decide whether the app is really “ready”: it fires the hooks for serve (after any auto-migrate) and for every command that runs against live data, and skips them for the schema commands. See [command_needs_ready].

App::build() still fires on_ready itself, which is right for a test or an embedder holding an App directly. Handing that app to dispatch leaves the hooks already fired, which is the gaps3 #41 bug: migrate against a fresh database ran every seed before the first table existed. dispatch warns when it sees that combination.