install_resources_parallel

Function install_resources_parallel 

Source
pub async fn install_resources_parallel(
    lockfile: &LockFile,
    manifest: &Manifest,
    project_dir: &Path,
    pb: &ProgressBar,
    cache: &Cache,
    force_refresh: bool,
    max_concurrency: Option<usize>,
) -> Result<usize>
👎Deprecated: Use install_resources with MultiPhaseProgress instead
Expand description

Install multiple resources in parallel using worktree-based concurrency.

This function performs parallel installation of all resources defined in the lockfile, using Git worktrees to enable safe concurrent access to repositories. Each dependency gets its own isolated worktree to prevent conflicts.

§Arguments

  • lockfile - The lockfile containing all resources to install
  • manifest - The project manifest for configuration
  • project_dir - The root project directory for installation
  • pb - Progress bar for user feedback
  • cache - Cache instance managing Git repositories and worktrees

§Parallel Architecture

The function uses several layers of concurrency control:

  • Tokio tasks: Each resource installation runs in its own async task
  • Unlimited task concurrency: Uses buffer_unordered(usize::MAX)
  • Parallelism control: –max-parallel flag controls concurrent operations
  • Worktree isolation: Each dependency gets its own worktree for safety

§Performance Optimizations

  • Stream processing: Uses futures::stream for efficient task scheduling
  • Context logging: Each operation includes dependency name for debugging
  • Worktree reuse: Cache layer optimizes Git repository access
  • Batched progress: Updates progress atomically to reduce contention
  • Deferred cleanup: Worktrees are left for reuse, cleaned up by cache commands

§Concurrency Control Flow

Lockfile Resources
      ↓
Async Task Stream (unlimited concurrency)
      ↓
install_resource_for_parallel() calls
      ↓
Cache worktree operations (parallelism-controlled)
      ↓
Git operations (controlled by --max-parallel)

§Examples

use agpm_cli::installer::install_resources_parallel;
use agpm_cli::lockfile::LockFile;
use agpm_cli::manifest::Manifest;
use agpm_cli::cache::Cache;
use agpm_cli::utils::progress::ProgressBar;
use std::path::Path;

let lockfile = LockFile::load(Path::new("agpm.lock"))?;
let manifest = Manifest::load(Path::new("agpm.toml"))?;
let cache = Cache::new()?;

// Count total resources for progress bar
let total = lockfile.agents.len() + lockfile.snippets.len()
    + lockfile.commands.len() + lockfile.scripts.len()
    + lockfile.hooks.len() + lockfile.mcp_servers.len();
let pb = ProgressBar::new(total as u64);

let count = install_resources_parallel(
    &lockfile,
    &manifest,
    Path::new("."),
    &pb,
    &cache,
    false,
    None,
).await?;

println!("Installed {} resources", count);

§Error Handling

  • Atomic failure: If any resource fails, the entire operation fails
  • Detailed context: Errors include specific resource and source information
  • Progress preservation: Progress updates continue even on partial failures
  • Resource cleanup: Failed operations don’t leave partial state

§Return Value

Returns the total number of resources successfully installed.