extracted create and clean resources from tap runner (#557)

This commit is contained in:
RoyUP9
2021-12-27 11:32:48 +02:00
committed by GitHub
parent 52ce6044ea
commit fd97a09624
7 changed files with 347 additions and 316 deletions

25
cli/utils/waitUtils.go Normal file
View File

@@ -0,0 +1,25 @@
package utils
import (
"context"
"github.com/up9inc/mizu/shared/logger"
"os"
"os/signal"
"syscall"
)
func WaitForFinish(ctx context.Context, cancel context.CancelFunc) {
logger.Log.Debugf("waiting for finish...")
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
// block until ctx cancel is called or termination signal is received
select {
case <-ctx.Done():
logger.Log.Debugf("ctx done")
break
case <-sigChan:
logger.Log.Debugf("Got termination signal, canceling execution...")
cancel()
}
}