feat(process): report live duration snapshots

This commit is contained in:
Virgil 2026-04-04 02:53:12 +00:00
parent 155f216a7c
commit a8c193d07c
2 changed files with 25 additions and 1 deletions

View file

@ -56,6 +56,11 @@ func (p *Process) Info() Info {
pid = p.cmd.Process.Pid
}
duration := p.Duration
if p.Status == StatusRunning {
duration = time.Since(p.StartedAt)
}
return Info{
ID: p.ID,
Command: p.Command,
@ -65,7 +70,7 @@ func (p *Process) Info() Info {
Running: p.Status == StatusRunning,
Status: p.Status,
ExitCode: p.ExitCode,
Duration: p.Duration,
Duration: duration,
PID: pid,
}
}

View file

@ -40,6 +40,25 @@ func TestProcess_Info_Pending(t *testing.T) {
assert.False(t, info.Running)
}
func TestProcess_Info_RunningDuration(t *testing.T) {
svc, _ := newTestService(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
proc, err := svc.Start(ctx, "sleep", "10")
require.NoError(t, err)
time.Sleep(10 * time.Millisecond)
info := proc.Info()
assert.True(t, info.Running)
assert.Equal(t, StatusRunning, info.Status)
assert.Greater(t, info.Duration, time.Duration(0))
cancel()
<-proc.Done()
}
func TestProcess_InfoSnapshot(t *testing.T) {
svc, _ := newTestService(t)