Refactor main.go loop. Fix panic.
This commit is contained in:
parent
6ac7073f27
commit
d11da90402
29
main.go
29
main.go
|
@ -82,24 +82,29 @@ func main() {
|
||||||
case evt := <-updates:
|
case evt := <-updates:
|
||||||
glog.V(10).Infof("recieved an update from the resource: %s", evt.Resource)
|
glog.V(10).Infof("recieved an update from the resource: %s", evt.Resource)
|
||||||
go func(r VaultEvent) {
|
go func(r VaultEvent) {
|
||||||
if err := processResource(evt.Resource, evt.Secret); err != nil {
|
|
||||||
glog.Errorf("failed to write out the update, error: %s", err)
|
|
||||||
}
|
|
||||||
toProcessLock.Lock()
|
toProcessLock.Lock()
|
||||||
defer toProcessLock.Unlock()
|
defer toProcessLock.Unlock()
|
||||||
for i, r := range toProcess {
|
switch r.Type {
|
||||||
if evt.Resource == r {
|
case EventTypeSuccess:
|
||||||
switch {
|
if err := processResource(evt.Resource, evt.Secret); err != nil {
|
||||||
case evt.Resource.maxRetries > 0 && evt.Resource.maxRetries < evt.Resource.retries:
|
glog.Errorf("failed to write out the update, error: %s", err)
|
||||||
toProcess = append(toProcess[:i], toProcess[i+1:]...)
|
}
|
||||||
failedResource = true
|
if options.oneShot {
|
||||||
break
|
for i, r := range toProcess {
|
||||||
case options.oneShot:
|
if evt.Resource == r {
|
||||||
if evt.Type == EventTypeSuccess {
|
|
||||||
toProcess = append(toProcess[:i], toProcess[i+1:]...)
|
toProcess = append(toProcess[:i], toProcess[i+1:]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case EventTypeFailure:
|
||||||
|
if evt.Resource.maxRetries > 0 && evt.Resource.maxRetries < evt.Resource.retries {
|
||||||
|
for i, r := range toProcess {
|
||||||
|
if evt.Resource == r {
|
||||||
|
toProcess = append(toProcess[:i], toProcess[i+1:]...)
|
||||||
|
failedResource = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(toProcess) == 0 {
|
if len(toProcess) == 0 {
|
||||||
glog.Infof("no resources left to process. exiting...")
|
glog.Infof("no resources left to process. exiting...")
|
||||||
|
|
Reference in a new issue