summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-10 16:05:10 +0800
committerKeuin <[email protected]>2022-09-10 16:05:10 +0800
commite999937d75d8e8c40b06add376ebac423b0c2079 (patch)
tree8a30abaa5fc8fc68d283e0be52a73ee83bdaf3a2 /main.go
parentf028bff042f471a68dff681af9c79ef96bc952e5 (diff)
Fix task is not properly restarted when the live is closed and started again.
Use more friendly log format to replace golang's default `log.Logger`. (not completed) Cleaner task status management.
Diffstat (limited to 'main.go')
-rw-r--r--main.go33
1 files changed, 24 insertions, 9 deletions
diff --git a/main.go b/main.go
index 6b68ee0..2b22cfc 100644
--- a/main.go
+++ b/main.go
@@ -1,7 +1,13 @@
package main
+/*
+In this file we implement config file and command line arguments parsing.
+Task lifecycle management are implemented in recording package.
+*/
+
import (
"bilibili-livestream-archiver/common"
+ "bilibili-livestream-archiver/logging"
"bilibili-livestream-archiver/recording"
"context"
"fmt"
@@ -127,23 +133,32 @@ func getTasks() (tasks []recording.TaskConfig) {
}
func main() {
- tasks := getTasks()
+ logger := log.Default()
+ taskConfigs := getTasks()
+ tasks := make([]recording.RunningTask, len(taskConfigs))
+ wg := sync.WaitGroup{}
+ ctxTasks, cancelTasks := context.WithCancel(context.Background())
fmt.Println("Record tasks:")
- for i, task := range tasks {
+ for i, task := range taskConfigs {
+ tasks[i] = recording.NewRunningTask(
+ taskConfigs[i],
+ ctxTasks,
+ func() { wg.Add(1) },
+ func() { wg.Done() },
+ logging.NewWrappedLogger(logger, fmt.Sprintf("room %v", task.RoomId)),
+ )
fmt.Printf("[%2d] %s\n", i+1, task)
}
fmt.Println("")
- logger := log.Default()
-
logger.Printf("Starting tasks...")
- wg := sync.WaitGroup{}
- ctx, cancelTasks := context.WithCancel(context.Background())
- for _, task := range tasks {
- wg.Add(1)
- go recording.RunTask(ctx, &wg, &task)
+ for i := range tasks {
+ err := tasks[i].StartTask()
+ if err != nil {
+ logger.Printf("Cannot start task %v (room %v): %v. Skip.", i, tasks[i].RoomId, err)
+ }
}
// listen on stop signals