Skip to content

Commit

Permalink
Add maxSeconds option
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfish-shogi committed Jul 9, 2024
1 parent 9368858 commit 0f7c0cb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

var opts struct {
IntervalMs uint
MaxSeconds float64
IsHLS bool
IsDASH bool
HLS struct {
Expand Down Expand Up @@ -65,6 +66,7 @@ func main() {
defaultExportDir := "" + time.Now().Format("export-20060102-150405")
flagSet = flag.NewFlagSet("antares", flag.ExitOnError)
flagSet.UintVar(&opts.IntervalMs, "interval", 0, "fixed manifest polling interval (milliseconds).")
flagSet.Float64Var(&opts.MaxSeconds, "maxSeconds", 0, "maximum seconds to monitor.")
flagSet.BoolVar(&opts.IsHLS, "hls", false, "This flag indicates URL argument is HLS.")
flagSet.BoolVar(&opts.IsDASH, "dash", false, "This flag indicates URL argument is DASH.")
flagSet.BoolVar(&opts.Export.Enable, "export", false, "Export raw data as local files.")
Expand Down Expand Up @@ -123,9 +125,16 @@ func main() {
config.RequestHeader = buildRequestHeader()
m := core.NewMonitor(config)

var timeout <-chan time.Time
if opts.MaxSeconds != 0 {
timeout = time.After(time.Second * time.Duration(opts.MaxSeconds))
}

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
select {
case <-timeout:
log.Print("reached maxSeconds")
case <-terminated:
case sig := <-sigCh:
log.Print("SIGNAL:", sig)
Expand Down

0 comments on commit 0f7c0cb

Please sign in to comment.