From a8c193d07caeabfcac5fdd2e62f42eb4370ab18b Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 02:53:12 +0000 Subject: [PATCH] feat(process): report live duration snapshots --- process.go | 7 ++++++- process_test.go | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/process.go b/process.go index 76cfc5d..63fc7a0 100644 --- a/process.go +++ b/process.go @@ -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, } } diff --git a/process_test.go b/process_test.go index 91c3405..ed91eb3 100644 --- a/process_test.go +++ b/process_test.go @@ -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)