mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-08 22:13:13 +08:00
fix: graceful stop
This commit is contained in:
@@ -378,9 +378,6 @@ func (b *Boomer) EnableGracefulQuit() {
|
|||||||
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
|
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
if b.mode == DistributedWorkerMode {
|
|
||||||
b.workerRunner.ignoreQuit = false
|
|
||||||
}
|
|
||||||
b.Quit()
|
b.Quit()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@@ -536,6 +533,7 @@ func (b *Boomer) GetCloseChan() chan bool {
|
|||||||
func (b *Boomer) Quit() {
|
func (b *Boomer) Quit() {
|
||||||
switch b.mode {
|
switch b.mode {
|
||||||
case DistributedWorkerMode:
|
case DistributedWorkerMode:
|
||||||
|
b.workerRunner.stop()
|
||||||
b.workerRunner.close()
|
b.workerRunner.close()
|
||||||
case DistributedMasterMode:
|
case DistributedMasterMode:
|
||||||
b.masterRunner.close()
|
b.masterRunner.close()
|
||||||
|
|||||||
@@ -620,6 +620,7 @@ func newWorkerRunner(masterHost string, masterPort int) (r *workerRunner) {
|
|||||||
nodeID: getNodeID(),
|
nodeID: getNodeID(),
|
||||||
tasksChan: make(chan *profileMessage, 10),
|
tasksChan: make(chan *profileMessage, 10),
|
||||||
mutex: sync.Mutex{},
|
mutex: sync.Mutex{},
|
||||||
|
ignoreQuit: false,
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -686,6 +687,10 @@ func (r *workerRunner) onMessage(msg *genericMessage) {
|
|||||||
log.Info().Msg("Recv stop message from master, all the goroutines are stopped")
|
log.Info().Msg("Recv stop message from master, all the goroutines are stopped")
|
||||||
r.client.sendChannel() <- newGenericMessage("client_stopped", nil, r.nodeID)
|
r.client.sendChannel() <- newGenericMessage("client_stopped", nil, r.nodeID)
|
||||||
case "quit":
|
case "quit":
|
||||||
|
r.stop()
|
||||||
|
if r.ignoreQuit {
|
||||||
|
break
|
||||||
|
}
|
||||||
r.close()
|
r.close()
|
||||||
log.Info().Msg("Recv quit message from master, all the goroutines are stopped")
|
log.Info().Msg("Recv quit message from master, all the goroutines are stopped")
|
||||||
}
|
}
|
||||||
@@ -797,10 +802,6 @@ func (r *workerRunner) stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *workerRunner) close() {
|
func (r *workerRunner) close() {
|
||||||
r.stop()
|
|
||||||
if r.ignoreQuit {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// waiting report finished
|
// waiting report finished
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
close(r.closeChan)
|
close(r.closeChan)
|
||||||
|
|||||||
Reference in New Issue
Block a user