pub fn effective_max_concurrent_jobs(
spec: Option<&ConcurrencySpec>,
) -> Option<NonZeroUsize>Expand description
The effective per-repository mover-Job concurrency cap:
concurrency.maxConcurrentJobs when set to a NON-ZERO value, else None
(uncapped). An absent concurrency block, an absent maxConcurrentJobs, and
an explicit 0 all mean the same thing — no limit — so all three collapse to
None.
Deliberately returns an Option<NonZeroUsize> rather than the plain scalar
effective_mass_deletion_threshold returns for its neighbouring breaker.
That resolver can use 0 as its own disable sentinel because the value it
yields is a count to compare against; here the value is a capacity, and
Some(0) would read as “admit nothing” — a repository that never runs a Job
again. Encoding “uncapped” in the Option and non-zero-ness in the type makes
that state unrepresentable rather than merely untested, and the caller’s
match/if let is then forced to spell out the uncapped path.
use kopiur_api::common::ConcurrencySpec;
use kopiur_api::consts::effective_max_concurrent_jobs;
// No block at all, no field, and an explicit 0 are the same state: uncapped.
assert_eq!(effective_max_concurrent_jobs(None), None);
assert_eq!(
effective_max_concurrent_jobs(Some(&ConcurrencySpec { max_concurrent_jobs: None })),
None,
);
assert_eq!(
effective_max_concurrent_jobs(Some(&ConcurrencySpec { max_concurrent_jobs: Some(0) })),
None,
);
// A positive value caps the pool.
assert_eq!(
effective_max_concurrent_jobs(Some(&ConcurrencySpec { max_concurrent_jobs: Some(3) }))
.map(|n| n.get()),
Some(3),
);