-
-
Save mvo5/6e0ac963aacce9d0c78f1c7cf829f9c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type appStartupOrder int | |
const ( | |
orderBefore appStartupOrder = iota | |
orderAfter | |
) | |
func (a appStartupOrder) String() string { | |
switch a { | |
case orderBefore: | |
return "before" | |
case orderAfter: | |
return "after" | |
} | |
panic(fmt.Sprintf("unsupported order: %v", a)) | |
} | |
func appStartOrdering(app *AppInfo, order appStartupOrder) []string { | |
switch order { | |
case orderBefore: | |
return app.Before | |
case orderAfter: | |
return app.After | |
} | |
panic(fmt.Sprintf("unsupported order: %v", order)) | |
} | |
func validateAppStartup(app *AppInfo, order appStartupOrder) error { | |
for _, dep := range appStartOrdering(app, order) { | |
// dependency is not defined | |
other, ok := app.Snap.Apps[dep] | |
if !ok { | |
return fmt.Errorf("cannot validate app %q startup ordering: needs to be started %s %q, but %q is not defined", | |
app.Name, order.String(), dep, dep) | |
} | |
// it depends on us in the same order, eg. foo is | |
// started after bar, but bar is to be started after foo | |
// as well, validate only one dependency step | |
otherDeps := appStartOrdering(other, order) | |
if strutil.ListContains(otherDeps, app.Name) { | |
return fmt.Errorf("cannot validate app %q startup ordering: needs to be started %s %q, but %q is declared to start %s %q", | |
app.Name, order, other.Name, other.Name, order, app.Name) | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment