fix(process): retain failed starts in service state
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
85cd6dd7c8
commit
8d1a0d0655
2 changed files with 20 additions and 3 deletions
11
service.go
11
service.go
|
|
@ -217,18 +217,25 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce
|
|||
if err := cmd.Start(); err != nil {
|
||||
proc.mu.Lock()
|
||||
proc.Status = StatusFailed
|
||||
proc.ExitCode = -1
|
||||
proc.Duration = time.Since(startedAt)
|
||||
proc.mu.Unlock()
|
||||
|
||||
s.mu.Lock()
|
||||
s.processes[id] = proc
|
||||
s.mu.Unlock()
|
||||
|
||||
close(proc.done)
|
||||
cancel()
|
||||
if c := s.coreApp(); c != nil {
|
||||
_ = c.ACTION(ActionProcessExited{
|
||||
ID: id,
|
||||
ExitCode: -1,
|
||||
Duration: time.Since(startedAt),
|
||||
Duration: proc.Duration,
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
return nil, coreerr.E("Service.StartWithOptions", "failed to start process", err)
|
||||
return proc, coreerr.E("Service.StartWithOptions", "failed to start process", err)
|
||||
}
|
||||
|
||||
proc.mu.Lock()
|
||||
|
|
|
|||
|
|
@ -78,8 +78,18 @@ func TestService_Start(t *testing.T) {
|
|||
t.Run("non-existent command", func(t *testing.T) {
|
||||
svc, _ := newTestService(t)
|
||||
|
||||
_, err := svc.Start(context.Background(), "nonexistent_command_xyz")
|
||||
proc, err := svc.Start(context.Background(), "nonexistent_command_xyz")
|
||||
assert.Error(t, err)
|
||||
require.NotNil(t, proc)
|
||||
assert.Equal(t, StatusFailed, proc.Status)
|
||||
assert.Equal(t, -1, proc.ExitCode)
|
||||
assert.NotNil(t, proc.Done())
|
||||
<-proc.Done()
|
||||
|
||||
got, getErr := svc.Get(proc.ID)
|
||||
require.NoError(t, getErr)
|
||||
assert.Equal(t, proc.ID, got.ID)
|
||||
assert.Equal(t, StatusFailed, got.Status)
|
||||
})
|
||||
|
||||
t.Run("empty command is rejected", func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue