Skip to content

refactor(hm-pipeline-ir): centralize duration-ms conversion in DurationMs#175

Closed
markovejnovic wants to merge 6 commits into
mainfrom
refactor/duration-ms-u128
Closed

refactor(hm-pipeline-ir): centralize duration-ms conversion in DurationMs#175
markovejnovic wants to merge 6 commits into
mainfrom
refactor/duration-ms-u128

Conversation

@markovejnovic

Copy link
Copy Markdown
Contributor

Generated by an AI agent.

…onMs

Introduce a `DurationMs(u64)` newtype in hm-pipeline-ir, carried on the wire
as a bare JSON number via `#[serde(transparent)]`, with a single saturating
`From<Duration>` conversion.

Replaces the ad-hoc `elapsed().as_millis() as u64` conversions on
`BuildEvent::{StepEnd,BuildEnd}` and `StepResultSummary`, which diverged
between lossy `as u64` (3 sites in scheduler) and saturating `try_from` (1
site in cloud watch). The conversion now has exactly one home.

u64 milliseconds stays the wire representation (~584M-year ceiling):
`serde_json` cannot round-trip `u128`, and a raw `Duration` serializes as an
awkward `{ secs, nanos }` pair non-Rust consumers must special-case. The
render side rebuilds a `Duration` via `DurationMs::as_duration()`.
- Replace the inherent `as_duration` with `impl From<DurationMs> for Duration`,
  mirroring the existing `From<Duration>` and reading as `Duration::from(ms)`.
- Derive `Display` via `derive_more` (newtype-forwards to the inner `u64`)
  instead of a hand-written impl; output is unchanged.
Blanket-impl CompactDuration for any `T: Into<Duration>` instead of only
`Duration`, so `DurationMs` (and any future duration newtype) gets `.compact()`
for free — no dependency edge into hm-pipeline-ir, since the impl never names
the concrete type. Render sites drop `Duration::from(*ms).compact()` back to
`ms.compact()`.
@markovejnovic

Copy link
Copy Markdown
Contributor Author

Subsumed by #176, which merged this branch in — all DurationMs commits live there now. Closing to avoid double-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant