forked from mystiq/dex
cmd/dex-worker: wait 'til connectors are available
Otherwise, if worker starts without connectors, and then connectors are added workers have to be restarted to pick up the changes.
This commit is contained in:
parent
188aa27c17
commit
3cd0d84e31
1 changed files with 18 additions and 4 deletions
|
@ -7,14 +7,16 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
|
|
||||||
|
"github.com/coreos/dex/connector"
|
||||||
"github.com/coreos/dex/db"
|
"github.com/coreos/dex/db"
|
||||||
pflag "github.com/coreos/dex/pkg/flag"
|
pflag "github.com/coreos/dex/pkg/flag"
|
||||||
"github.com/coreos/dex/pkg/log"
|
"github.com/coreos/dex/pkg/log"
|
||||||
|
ptime "github.com/coreos/dex/pkg/time"
|
||||||
"github.com/coreos/dex/server"
|
"github.com/coreos/dex/server"
|
||||||
|
|
||||||
"github.com/coreos/pkg/flagutil"
|
"github.com/coreos/pkg/flagutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -150,9 +152,21 @@ func main() {
|
||||||
log.Fatalf("Unable to build Server: %v", err)
|
log.Fatalf("Unable to build Server: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfgs, err := srv.ConnectorConfigRepo.All()
|
var cfgs []connector.ConnectorConfig
|
||||||
if err != nil {
|
var sleep time.Duration
|
||||||
log.Fatalf("Unable to fetch connector configs from repo: %v", err)
|
for {
|
||||||
|
var err error
|
||||||
|
cfgs, err = srv.ConnectorConfigRepo.All()
|
||||||
|
if len(cfgs) > 0 && err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
sleep = ptime.ExpBackoff(sleep, time.Minute)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Unable to load connectors, retrying in %v: %v", sleep, err)
|
||||||
|
} else {
|
||||||
|
log.Errorf("No connectors, will wait. Retrying in %v.", sleep)
|
||||||
|
}
|
||||||
|
time.Sleep(sleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cfg := range cfgs {
|
for _, cfg := range cfgs {
|
||||||
|
|
Loading…
Reference in a new issue