diff --git a/process_test.go b/process_test.go index f7590d0..91c3405 100644 --- a/process_test.go +++ b/process_test.go @@ -28,6 +28,18 @@ func TestProcess_Info(t *testing.T) { assert.Greater(t, info.Duration, time.Duration(0)) } +func TestProcess_Info_Pending(t *testing.T) { + proc := &Process{ + ID: "pending", + Status: StatusPending, + done: make(chan struct{}), + } + + info := proc.Info() + assert.Equal(t, StatusPending, info.Status) + assert.False(t, info.Running) +} + func TestProcess_InfoSnapshot(t *testing.T) { svc, _ := newTestService(t) diff --git a/service.go b/service.go index c2d22c2..0df87ad 100644 --- a/service.go +++ b/service.go @@ -198,7 +198,7 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce Dir: opts.Dir, Env: append([]string(nil), opts.Env...), StartedAt: startedAt, - Status: StatusRunning, + Status: StatusPending, cmd: cmd, ctx: procCtx, cancel: cancel, @@ -211,6 +211,10 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce // Start the process if err := cmd.Start(); err != nil { + proc.mu.Lock() + proc.Status = StatusFailed + proc.mu.Unlock() + cancel() if c := s.coreApp(); c != nil { _ = c.ACTION(ActionProcessExited{ @@ -223,6 +227,10 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce return nil, coreerr.E("Service.StartWithOptions", "failed to start process", err) } + proc.mu.Lock() + proc.Status = StatusRunning + proc.mu.Unlock() + // Store process s.mu.Lock() s.processes[id] = proc