fix(process): emit kill action immediately
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
9a93ebea66
commit
c60f355b25
2 changed files with 27 additions and 4 deletions
12
process.go
12
process.go
|
|
@ -38,6 +38,7 @@ type ManagedProcess struct {
|
|||
gracePeriod time.Duration
|
||||
killGroup bool
|
||||
lastSignal string
|
||||
killEmitted bool
|
||||
}
|
||||
|
||||
// Process is kept as a compatibility alias for ManagedProcess.
|
||||
|
|
@ -219,3 +220,14 @@ func (p *ManagedProcess) requestedSignal() string {
|
|||
defer p.mu.RUnlock()
|
||||
return p.lastSignal
|
||||
}
|
||||
|
||||
func (p *ManagedProcess) markKillEmitted() bool {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.killEmitted {
|
||||
return false
|
||||
}
|
||||
p.killEmitted = true
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
19
service.go
19
service.go
|
|
@ -230,10 +230,7 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) core.Re
|
|||
close(proc.done)
|
||||
|
||||
if status == StatusKilled {
|
||||
_ = s.Core().ACTION(ActionProcessKilled{
|
||||
ID: id,
|
||||
Signal: killedSignal,
|
||||
})
|
||||
s.emitKilledAction(proc, killedSignal)
|
||||
}
|
||||
s.Core().ACTION(ActionProcessExited{
|
||||
ID: id,
|
||||
|
|
@ -308,6 +305,7 @@ func (s *Service) Kill(id string) error {
|
|||
if err := proc.Kill(); err != nil {
|
||||
return err
|
||||
}
|
||||
s.emitKilledAction(proc, proc.requestedSignal())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -490,3 +488,16 @@ func normalizeSignalName(sig syscall.Signal) string {
|
|||
return sig.String()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) emitKilledAction(proc *ManagedProcess, signal string) {
|
||||
if proc == nil || !proc.markKillEmitted() {
|
||||
return
|
||||
}
|
||||
if signal == "" {
|
||||
signal = "SIGKILL"
|
||||
}
|
||||
_ = s.Core().ACTION(ActionProcessKilled{
|
||||
ID: proc.ID,
|
||||
Signal: signal,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue