domain/record, runner: add DurationMS to RunRecord (T2.1, T2.2)

Add DurationMS int64 field to RunRecord and measure wall-clock
start→finish in RunJob; StartOnly jobs record 0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mixeme
2026-06-24 08:09:59 +03:00
parent 183ea1b125
commit 42d73b9eb0
2 changed files with 22 additions and 16 deletions
+1
View File
@@ -12,4 +12,5 @@ type RunRecord struct {
Detail string `yaml:"detail"` Detail string `yaml:"detail"`
LogFile string `yaml:"log_file,omitempty"` LogFile string `yaml:"log_file,omitempty"`
Output string `yaml:"output,omitempty"` Output string `yaml:"output,omitempty"`
DurationMS int64 `yaml:"duration_ms,omitempty"`
} }
+5
View File
@@ -27,9 +27,12 @@ func RunJob(ctx context.Context, job *domain.Job, trigger string, logsDir string
var output string var output string
var state string var state string
var detail string var detail string
var durationMS int64
if job.StartOnly { if job.StartOnly {
invocation := jobInvocation(context.Background(), *job) invocation := jobInvocation(context.Background(), *job)
state, detail, output = startJobOnly(invocation, *job, started) state, detail, output = startJobOnly(invocation, *job, started)
// StartOnly jobs don't wait for process exit, so no meaningful duration.
durationMS = 0
} else { } else {
var stdoutBuf strings.Builder var stdoutBuf strings.Builder
var stderrBuf strings.Builder var stderrBuf strings.Builder
@@ -44,6 +47,7 @@ func RunJob(ctx context.Context, job *domain.Job, trigger string, logsDir string
err := command.Run() err := command.Run()
duration := time.Since(started).Round(time.Millisecond) duration := time.Since(started).Round(time.Millisecond)
durationMS = duration.Milliseconds()
output = formatOutput(stdoutBuf.String(), stderrBuf.String()) output = formatOutput(stdoutBuf.String(), stderrBuf.String())
state, detail = runStateDetail(err, runCtx.Err(), duration) state, detail = runStateDetail(err, runCtx.Err(), duration)
} }
@@ -64,6 +68,7 @@ func RunJob(ctx context.Context, job *domain.Job, trigger string, logsDir string
Detail: detail, Detail: detail,
LogFile: logFile, LogFile: logFile,
Output: output, Output: output,
DurationMS: durationMS,
} }
} }