Skip to content

Instantly share code, notes, and snippets.

@calebamiles
Last active September 21, 2015 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calebamiles/d5229b5a86caf327ad6a to your computer and use it in GitHub Desktop.
Save calebamiles/d5229b5a86caf327ad6a to your computer and use it in GitHub Desktop.
type selectionFunc func(config.CPI) (string, error)
type reservationFunc func(config.CPI, string) (string, error)
func tryReservation(c config.CPI, choose selectionFunc, reserve reservationFunc) (string, error) {
var cid string
Loop:
for i := 0; i < maxRetries; i++ {
nodeID, loopErr := choose(c)
if loopErr != nil {
//log loopErr
continue
}
cid, loopErr = reserve(nodeID)
if loopErr != nil {
//log loopErr
continue
}
if cid != "" {
break Loop
}
}
if cid == "" {
return "", errors.New("unable to reserve node")
}
return cid, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment