feat(process): honor pending lifecycle
This commit is contained in:
parent
1ccc61848b
commit
31be7280a6
2 changed files with 21 additions and 1 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
10
service.go
10
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue