mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Fix race condition during initialization (#163)
Currently, async workers are started before HTTP interface is available
to get their requests. It fixes by ensuring that async workers are
started after HTTP interface is up.
Essentially we are getting rid of an error message during bootstrap:
ERRO[0000] Could not fetch task error=Get http://127.0.0.1:8080/tasks: dial tcp 127.0.0.1:8080: getsockopt: connection refused
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
34b4b25092
commit
df3d5b48ce
30
main.go
30
main.go
@@ -6,8 +6,8 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"cirello.io/supervisor"
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/datastore"
|
||||
@@ -79,16 +79,24 @@ func main() {
|
||||
log.WithError(err).Fatalln("Failed to create a runner")
|
||||
}
|
||||
|
||||
apiURL, port, numAsync := viper.GetString(envAPIURL), viper.GetString(envPort), viper.GetInt(envNumAsync)
|
||||
log.Debug("async workers:", numAsync)
|
||||
var wgAsync sync.WaitGroup
|
||||
if numAsync > 0 {
|
||||
wgAsync.Add(1)
|
||||
go runner.RunAsyncRunner(ctx, &wgAsync, apiURL, port, numAsync)
|
||||
svr := &supervisor.Supervisor{
|
||||
Log: func(msg interface{}) {
|
||||
log.Debug("supervisor: ", msg)
|
||||
},
|
||||
}
|
||||
|
||||
srv := server.New(ds, mqType, rnr)
|
||||
go srv.Run(ctx)
|
||||
<-ctx.Done()
|
||||
wgAsync.Wait()
|
||||
svr.AddFunc(func(ctx context.Context) {
|
||||
srv := server.New(ds, mqType, rnr)
|
||||
srv.Run(ctx)
|
||||
})
|
||||
|
||||
apiURL, port, numAsync := viper.GetString(envAPIURL), viper.GetString(envPort), viper.GetInt(envNumAsync)
|
||||
log.Debug("async workers:", numAsync)
|
||||
if numAsync > 0 {
|
||||
svr.AddFunc(func(ctx context.Context) {
|
||||
runner.RunAsyncRunner(ctx, apiURL, port, numAsync)
|
||||
})
|
||||
}
|
||||
|
||||
svr.Serve(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user