Add SIGTERM monitoring (#101)
This commit is contained in:
parent
3949e49b3b
commit
ec480844a8
@ -4,7 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,6 +69,8 @@ func (j *Job) Start() {
|
|||||||
j.Output.Banner()
|
j.Output.Banner()
|
||||||
}
|
}
|
||||||
j.Running = true
|
j.Running = true
|
||||||
|
// Monitor for SIGTERM and do cleanup properly (writing the output files etc)
|
||||||
|
j.interruptMonitor()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go j.runProgress(&wg)
|
go j.runProgress(&wg)
|
||||||
@ -105,6 +110,17 @@ func (j *Job) Start() {
|
|||||||
return
|
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) {
|
func (j *Job) runProgress(wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
j.startTime = time.Now()
|
j.startTime = time.Now()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user