a write answers before the site hook starts and gc runs
Signed-off-by: dawn <90008@klbr.net>
103 unmodified linesExpand all104105106107108109110111112113114115116117118119120121305 unmodified linesExpand all103 unmodified linesExpand all /// skip updating owner declarations on their pds #[arg(long)] no_declarations: bool, }, /// start the site hook and collect garbage after a write's activation #[command(hide = true)] AfterActivation { generation: String, #[arg(long)] previous: Option<String>, /// when the activation happened, in unix seconds #[arg(long)] at: u64, }, /// ask configured crawlers to crawl this knot now Crawl, /// run repack, gc or prune on one or all hosted repos under the build lock Maintenance {305 unmodified linesExpand all200 unmodified linesExpand all20120220320420520620720820921021121221393 unmodified lines200 unmodified linesExpand all keys::sync(&config, false), ); keys } Command::AfterActivation { generation, previous, at, } => activate::after_activation(&config, &generation, previous.as_deref(), at), Command::Crawl => { crawl::request_all(&config).await; Ok(()) }93 unmodified lines44 unmodified lines4546474849505152495354555657307 unmodified linesExpand all36536636736836937037137237337437537637737837936536636736836937037137237337437537638038138238338438538638738838939039139239339439523 unmodified lines41942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047141447247347447547647747847948048148248348426 unmodified lines44 unmodified linespub async fn activate( config: Arc<ValidatedConfig>, generation: &str,) -> anyhow::Result<ActivationResult> { let options = ActivateOptions { detached: true, ..ActivateOptions::default() }; activate_with(config, generation, ActivateOptions::default()).await activate_with(config, generation, options).await}
fn resolve_generation(output_root: &Path, given: &str) -> anyhow::Result<String> { let full = given.len() == 64;307 unmodified linesExpand all fragments_total, t_activation.elapsed(), )); crate::tombstone::clear(&config.output_root)?; let collected = if options.detached { let at = activated_at_unix.to_string(); let mut args = vec!["after-activation", generation, "--at", &at]; if let Some(previous) = &previous_manifest { args.extend(["--previous", &previous.generation_id]); } if let Err(error) = crate::git_ssh::spawn_detached(&config, args) { tracing::warn!("site hook and gc skipped: {error:#}"); } Ok(crate::gc::Removed::default()) } else { crate::generate::site_hook::after_activation( &config, &crate::generate::site_hook::Activation { generation_dir: &generation_dir, manifest: &manifest, previous: previous_manifest.as_ref(), rollback: options.rollback, activated_at_unix, }, );
let collected = crate::gc::collect(&config.output_root, config.activate.keep_generations); crate::generate::site_hook::after_activation( &config, &crate::generate::site_hook::Activation { generation_dir: &generation_dir, manifest: &manifest, previous: previous_manifest.as_ref(), rollback: options.rollback, activated_at_unix, }, ); crate::gc::collect(&config.output_root, config.activate.keep_generations) }; if !crate::out::is_transport() { match firehose { Ok(0) => {} Ok(appended) => eprintln!("firehose: {appended} frames"),23 unmodified lines crate::pds::publish_all(config.clone(), changed_repos).await; }}
/// a newer activation starts its own hook, so an older one only collectspub fn after_activation( config: &ValidatedConfig, generation: &str, previous: Option<&str>, activated_at_unix: u64,) -> anyhow::Result<()> { let generations = config.output_root.join("generations"); let hook = { let _output_lock = crate::output::lock(&config.output_root)?; let current = publish::current_generation(&config.output_root); let hook = match &config.activate.site_hook { Some(_) if current.as_deref() == Some(generation) => { let generation_dir = generations.join(generation); let manifest = GenerationManifest::load(&generation_dir)?; let previous = previous.and_then(|previous| { GenerationManifest::load(&generations.join(previous)).ok() }); let activation = crate::generate::site_hook::Activation { generation_dir: &generation_dir, manifest: &manifest, previous: previous.as_ref(), rollback: false, activated_at_unix, }; crate::generate::site_hook::write_hook(config, &activation) .inspect_err(|error| tracing::warn!("site hook skipped: {error:#}")) .ok() } _ => None, }; let removed = crate::gc::collect(&config.output_root, config.activate.keep_generations)?; if !removed.is_empty() { eprintln!("gc: {removed}"); } hook }; if let (Some(hook), Some(path)) = (&config.activate.site_hook, hook) { crate::generate::site_hook::start(config, hook, &path)?; } Ok(())}
pub async fn run( config: Arc<ValidatedConfig>, generation: &str, rollback: bool,) -> anyhow::Result<()> { let generation = resolve_generation(&config.output_root, generation)?; let result = activate_with(config.clone(), &generation, ActivateOptions { rollback }).await?; let result = activate_with( config.clone(), &generation, ActivateOptions { rollback, ..ActivateOptions::default() }, ) .await?; post_activate(config, &result.changed_repos, true).await; Ok(())}
26 unmodified lines8 unmodified lines9101112131415161718568 unmodified linesExpand all8 unmodified lines
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]pub struct ActivateOptions { pub rollback: bool, /// the site hook and gc run in a process of their own, so a write answers without them pub detached: bool,}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]pub struct ActivationTelemetry {568 unmodified linesExpand all314 unmodified linesExpand all31531631731831931932032132232332432532632753 unmodified lines314 unmodified linesExpand all .collect()}
/// the renderer keeps the lock after this process exits, so the fd has to survive exec.fn start(config: &ValidatedConfig, hook: &SiteHook, hook_json: &Path) -> anyhow::Result<()> {pub(crate) fn start( config: &ValidatedConfig, hook: &SiteHook, hook_json: &Path,) -> anyhow::Result<()> { use std::os::fd::AsRawFd as _; use std::os::unix::process::CommandExt as _;
let root = &config.output_root;53 unmodified lines