Manager: replace "direction=twoway" with "is_twoway=true" in config
A boolean provides less context to the setting, so it's not as easy to understand. However, in this case the simple case will have `is_twoway=false` and be ommitted from the configuration file. This makes the simple case even simpler.
This commit is contained in:
parent
5728884fed
commit
bedf7869f8
@ -51,7 +51,6 @@ var defaultConfig = Conf{
|
||||
Variables: map[string]Variable{
|
||||
// The default commands assume that the executables are available on $PATH.
|
||||
"blender": {
|
||||
Direction: "oneway",
|
||||
Values: VariableValues{
|
||||
VariableValue{Platform: "linux", Value: "blender --factory-startup --background"},
|
||||
VariableValue{Platform: "windows", Value: "blender.exe --factory-startup --background"},
|
||||
@ -59,7 +58,6 @@ var defaultConfig = Conf{
|
||||
},
|
||||
},
|
||||
"ffmpeg": {
|
||||
Direction: "oneway",
|
||||
Values: VariableValues{
|
||||
VariableValue{Platform: "linux", Value: "ffmpeg"},
|
||||
VariableValue{Platform: "windows", Value: "ffmpeg.exe"},
|
||||
@ -68,7 +66,7 @@ var defaultConfig = Conf{
|
||||
},
|
||||
// TODO: determine useful defaults for these.
|
||||
// "job_storage": {
|
||||
// Direction: "twoway",
|
||||
// IsTwoWay: true,
|
||||
// Values: VariableValues{
|
||||
// VariableValue{Platform: "linux", Value: "/shared/flamenco/jobs"},
|
||||
// VariableValue{Platform: "windows", Value: "S:/flamenco/jobs"},
|
||||
@ -76,7 +74,7 @@ var defaultConfig = Conf{
|
||||
// },
|
||||
// },
|
||||
// "render": {
|
||||
// Direction: "twoway",
|
||||
// IsTwoWay: true,
|
||||
// Values: VariableValues{
|
||||
// VariableValue{Platform: "linux", Value: "/shared/flamenco/render"},
|
||||
// VariableValue{Platform: "windows", Value: "S:/flamenco/render"},
|
||||
|
@ -145,8 +145,7 @@ type Conf struct {
|
||||
|
||||
// Variable defines a configuration variable.
|
||||
type Variable struct {
|
||||
// Either "oneway" or "twoway"
|
||||
Direction string `yaml:"direction" json:"direction"`
|
||||
IsTwoWay bool `yaml:"is_twoway,omitempty" json:"is_twoway,omitempty"`
|
||||
// Mapping from variable value to audience/platform definition.
|
||||
Values VariableValues `yaml:"values" json:"values"`
|
||||
}
|
||||
@ -285,7 +284,7 @@ func (c *Conf) constructVariableLookupTable(logLevel zerolog.Level) {
|
||||
// Two-way values should not end in path separator.
|
||||
// Given a variable 'apps' with value '/path/to/apps',
|
||||
// '/path/to/apps/blender' should be remapped to '{apps}/blender'.
|
||||
if variable.Direction == "twoway" {
|
||||
if variable.IsTwoWay {
|
||||
if strings.Contains(value.Value, "\\") {
|
||||
log.Warn().
|
||||
Str("variable", name).
|
||||
@ -346,20 +345,7 @@ func (c *Conf) ExpandVariables(valueToExpand string, audience VariableAudience,
|
||||
// checkVariables performs some basic checks on variable definitions.
|
||||
// All errors are logged, not returned.
|
||||
func (c *Conf) checkVariables() {
|
||||
directionNames := []string{"oneway", "twoway"}
|
||||
validDirections := map[string]bool{}
|
||||
for _, direction := range directionNames {
|
||||
validDirections[direction] = true
|
||||
}
|
||||
|
||||
for name, variable := range c.Variables {
|
||||
if !validDirections[variable.Direction] {
|
||||
log.Error().
|
||||
Str("name", name).
|
||||
Str("direction", variable.Direction).
|
||||
Strs("validChoices", directionNames).
|
||||
Msg("variable has invalid direction")
|
||||
}
|
||||
for valueIndex, value := range variable.Values {
|
||||
// No platforms at all.
|
||||
if value.Platform == "" && len(value.Platforms) == 0 {
|
||||
|
@ -17,19 +17,9 @@ func TestDefaultSettings(t *testing.T) {
|
||||
assert.Equal(t, defaultConfig.TaskLogsPath, config.TaskLogsPath)
|
||||
assert.Equal(t, defaultConfig.DatabaseDSN, config.DatabaseDSN)
|
||||
|
||||
assert.Contains(t, config.Variables, "job_storage")
|
||||
assert.Contains(t, config.Variables, "render")
|
||||
assert.Equal(t, "oneway", config.Variables["ffmpeg"].Direction)
|
||||
assert.Equal(t, false, config.Variables["ffmpeg"].IsTwoWay)
|
||||
assert.Equal(t, "ffmpeg", config.Variables["ffmpeg"].Values[0].Value)
|
||||
assert.Equal(t, "linux", config.Variables["ffmpeg"].Values[0].Platform)
|
||||
|
||||
linuxPVars, ok := config.VariablesLookup["workers"]["linux"]
|
||||
assert.True(t, ok, "workers/linux should have variables: %v", config.VariablesLookup)
|
||||
assert.Equal(t, "/shared/flamenco/jobs", linuxPVars["job_storage"])
|
||||
|
||||
winPVars, ok := config.VariablesLookup["users"]["windows"]
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "S:/flamenco/jobs", winPVars["job_storage"])
|
||||
}
|
||||
|
||||
func TestVariableValidation(t *testing.T) {
|
||||
@ -47,3 +37,6 @@ func TestVariableValidation(t *testing.T) {
|
||||
assert.Equal(t, c.Variables["blender"].Values[0].Value, "/path/to/blender")
|
||||
assert.Equal(t, c.Variables["blender"].Values[1].Value, "/valid/path/blender")
|
||||
}
|
||||
|
||||
// TODO: Test two-way variables. Even though they're not currently in the
|
||||
// default configuration, they should work.
|
||||
|
Loading…
Reference in New Issue
Block a user