From 12ed615f538295dadbbce213d4efbdf7fe15b6eb Mon Sep 17 00:00:00 2001 From: giongto35 Date: Mon, 3 Jun 2019 02:41:35 +0800 Subject: [PATCH] Start worker port from 9000 (#47) --- cmd/main.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 31340b9b..9de1d2aa 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -54,9 +54,19 @@ func initializeWorker() { }() go worker.Run() - port := rand.Int()%100 + 8000 - log.Println("Listening at port: localhost:", port) - http.ListenAndServe(":"+strconv.Itoa(port), nil) + port := 9000 + // It's recommend to run one worker on one instance. This logic is to make sure more than 1 workers still work + for { + log.Println("Listening at port: localhost:", port) + err := http.ListenAndServe(":"+strconv.Itoa(port), nil) + if err != nil { + port++ + } + if port == 9100 { + // Cannot find port + return + } + } } func monitor() {