git-ents.gitmain
⌘K
foforge
commit 848dd34
refactor: name queue job files with a uuid instead of a hand-rolled stem

nanos-since-epoch + pid + an atomic counter reimplemented what a v4 uuid already gives for free: a collision-proof name for concurrent pushes.

deps: add uuid refactor: replace checks.rs’s job_stem with uuid::Uuid::new_v4 Assisted-by: Claude:claude-sonnet-5

Joseph D. Carpinelli · 1 month ago

Reviews

No reviews of this commit yet — record a verdict below.

Start a review

verdict

Cargo.lock @@ -1054,6 +1054,7 @@ "rstest", "tempfile", "tokio", + "uuid", ] [[package]] @@ -3244,6 +3245,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "1.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf80a72845275afea99e7f2b434723d3bc7e38470fcd1c7ed39a599c73319a53" +dependencies = [ + "getrandom", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "version_check" version = "0.9.5"
Cargo.toml @@ -59,6 +59,7 @@ "io-util", "sync", ] } +uuid = { version = "1", features = ["v4"] } # These lint configurations were originally pulled from [Evan Schwartz][1]. # [1]: https://emschwartz.me/your-clippy-config-should-be-stricter/
crates/git-ents-server/Cargo.toml @@ -25,6 +25,7 @@ maud = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true } +uuid = { workspace = true } [dev-dependencies] rstest = { workspace = true }
crates/git-ents-server/src/checks.rs @@ -27,8 +27,7 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::sync::Arc; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use std::time::Duration; use git_ents::checks::{self, Check, RunOutcome}; use tokio::sync::Mutex; @@ -262,16 +261,10 @@ Ok(()) } -/// A unique job file stem (`<nanos>-<pid>-<counter>`) so concurrent pushes never -/// collide on a queue file name. +/// A unique job file stem so concurrent pushes never collide on a queue file +/// name. fn job_stem() -> String { - static COUNTER: AtomicU64 = AtomicU64::new(0); - let nanos = SystemTime::now() - .duration_since(UNIX_EPOCH) - .map(|d| d.as_nanos()) - .unwrap_or(0); - let n = COUNTER.fetch_add(1, Ordering::Relaxed); - format!("{nanos}-{}-{n}", std::process::id()) + uuid::Uuid::new_v4().to_string() } /// Parse a queued job file (`repo`, new oid, ref, one per line), or `None` when