Skip to main content

execute

Function execute 

Source
pub async fn execute<H, F, G, C>(
    plan: &Plan,
    manifest: &mut Manifest,
    albums: &mut BTreeMap<String, AlbumArt>,
    playlists: &mut BTreeMap<String, PlaylistState>,
    desired: &[Desired],
    synced: &HashMap<String, AlignedLyrics>,
    ports: Ports<'_, H, F, G, C>,
    opts: &ExecOptions,
) -> ExecOutcome
where H: Http, F: Filesystem, G: Ffmpeg, C: Clock,
Expand description

Apply plan to disk, updating manifest and albums in place, and return the outcome.

desired carries the per-clip metadata and art hashes plus the source modes that decide the preserve marker; it is indexed by clip id (and by target path, for renames) so each written entry records the right hashes and protection. albums is the album-art store, keyed by stable root id: folder-art writes and deletes record their state there rather than on the per-clip manifest. ports bundles the authenticated client and the network, disk, transcode, and backoff ports. A single clip’s failure never aborts the run, except an auth failure or a full disk, which stop it with RunStatus::AuthAborted or RunStatus::DiskFull.

Audio-producing (Download / Reformat), fetched-artifact (WriteArtifact with no inline content), and stem (WriteStem) actions all run their slow, side-effect-free work concurrently, bounded by ExecOptions::concurrency: WAV render + CDN download + transcode + tag for audio; CDN fetch + optional WebP transcode for artifacts; WAV render + CDN download for stems. Order-sensitive Suno API calls (WAV render initiation and poll) are serialised behind an async mutex over the shared SunoClient, keeping the adaptive limiter and JWT refresh correct. The remaining actions (retag, rename, delete, artifact deletes, and inline artifact writes) run serially in plan order.

The outcome is deterministic regardless of completion order: all prepared results are committed to the manifest in plan-index order, so the same plan always yields the same manifest and counts whatever the concurrency level. A per-clip failure is recorded and the run continues; only an auth failure or a full disk aborts, and it does so promptly by stopping further concurrent work.

synced carries this run’s fetched aligned (synced) lyrics keyed by clip id; it is the caller’s IO result, not part of the pure plan. Audio tagging embeds a clip’s entry as an MP3 SYLT frame and as the plain USLT/LYRICS text (FLAC), so a clip absent from the map (an instrumental, a WAV target, or a run with the feature off) is tagged exactly as before. The synced .lrc sidecar itself is a generated artifact whose body the caller has already resolved into the plan, so it is written like any other text sidecar.