summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-08 00:43:12 +0800
committerKeuin <[email protected]>2022-09-08 00:43:12 +0800
commitb473c12438438a4709708d5d4ecd403d81f11e03 (patch)
tree01f49b3176098edaf49b60769ae69a6194b331ca
parenta720c2c16b442b668db465fbbc70740cfc7ddee4 (diff)
Bugfix: process won't quit when sending Ctrl-C.
Print runtime information to logs in main() function.
-rw-r--r--main.go14
-rw-r--r--recording/runner.go5
2 files changed, 15 insertions, 4 deletions
diff --git a/main.go b/main.go
index 792df07..37083b9 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/akamensky/argparse"
"github.com/spf13/viper"
+ "log"
"os"
"os/signal"
"sync"
@@ -114,8 +115,11 @@ func main() {
for _, task := range tasks {
fmt.Println(task.String())
}
- fmt.Println("========================")
+ fmt.Println("")
+ logger := log.Default()
+
+ logger.Printf("Starting tasks...")
chResult := make(chan recording.TaskResult)
wg := sync.WaitGroup{}
ctx, cancelTasks := context.WithCancel(context.Background())
@@ -131,18 +135,20 @@ func main() {
chSigInt := make(chan os.Signal)
signal.Notify(chSigInt, os.Interrupt)
+loop:
for {
select {
case <-chSigInt:
- fmt.Println("Stopping...")
+ logger.Println("YABR is stopped.")
cancelTasks()
+ break loop
case result := <-chResult:
err := result.Error
if err != nil {
- fmt.Printf("A task stopped with an error (room %v): %v\n",
+ logger.Printf("A task stopped with an error (room %v): %v\n",
result.Task.RoomId, result.Error)
} else {
- fmt.Printf("Task stopped (room %v): %v\n",
+ logger.Printf("Task stopped (room %v): %v\n",
result.Task.RoomId, result.Task.String())
}
}
diff --git a/recording/runner.go b/recording/runner.go
index d4e5a96..bcea9a7 100644
--- a/recording/runner.go
+++ b/recording/runner.go
@@ -201,6 +201,11 @@ func watcherRecoverableLoop(
chWatcherEvent,
)
+ // the context is cancelled, stop watching
+ if errors.Is(err, context.Canceled) {
+ return
+ }
+
switch errReason {
case ErrSuccess:
// stop normally, the context is closed