From a4614150389f68264ca6c5356d4bf31f29fdce14 Mon Sep 17 00:00:00 2001 From: giongto35 Date: Tue, 21 May 2019 23:54:31 +0800 Subject: [PATCH] Worker listen to random port so we can run multiple worker --- cmd/main.go | 5 ++++- vpx-encoder/encoder.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index b34ee26e..a30918ae 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,6 +7,7 @@ import ( "net/http" _ "net/http/pprof" "runtime" + "strconv" "strings" "time" @@ -63,7 +64,9 @@ func initializeWorker() { }() go worker.Run() - http.ListenAndServe(":8001", nil) + port := rand.Int()%100 + 8000 + log.Println("Listening at port: localhost:", port) + http.ListenAndServe(":"+strconv.Itoa(port), nil) } func monitor() { diff --git a/vpx-encoder/encoder.go b/vpx-encoder/encoder.go index 3f85f816..a247bf69 100644 --- a/vpx-encoder/encoder.go +++ b/vpx-encoder/encoder.go @@ -165,6 +165,11 @@ func (v *VpxEncoder) startLooping() { log.Println("Encoding time: ", time.Now().Sub(beginEncoding)) } } + if v.Done == true { + // The first time we see IsRunning set to false, we release and return + v.Release() + return + } } // Release release memory and stop loop