Add SIGTERM monitoring (#101)
This commit is contained in:
parent
3949e49b3b
commit
ec480844a8
@ -4,7 +4,10 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -66,6 +69,8 @@ func (j *Job) Start() {
|
||||
j.Output.Banner()
|
||||
}
|
||||
j.Running = true
|
||||
// Monitor for SIGTERM and do cleanup properly (writing the output files etc)
|
||||
j.interruptMonitor()
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go j.runProgress(&wg)
|
||||
@ -105,6 +110,17 @@ func (j *Job) Start() {
|
||||
return
|
||||
}
|
||||
|
||||
func (j *Job) interruptMonitor() {
|
||||
sigChan := make(chan os.Signal, 2)
|
||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
for _ = range sigChan {
|
||||
j.Error = "Caught keyboard interrupt (Ctrl-C)\n"
|
||||
j.Stop()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (j *Job) runProgress(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
j.startTime = time.Now()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user