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{
|
Variables: map[string]Variable{
|
||||||
// The default commands assume that the executables are available on $PATH.
|
// The default commands assume that the executables are available on $PATH.
|
||||||
"blender": {
|
"blender": {
|
||||||
Direction: "oneway",
|
|
||||||
Values: VariableValues{
|
Values: VariableValues{
|
||||||
VariableValue{Platform: "linux", Value: "blender --factory-startup --background"},
|
VariableValue{Platform: "linux", Value: "blender --factory-startup --background"},
|
||||||
VariableValue{Platform: "windows", Value: "blender.exe --factory-startup --background"},
|
VariableValue{Platform: "windows", Value: "blender.exe --factory-startup --background"},
|
||||||
@ -59,7 +58,6 @@ var defaultConfig = Conf{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"ffmpeg": {
|
"ffmpeg": {
|
||||||
Direction: "oneway",
|
|
||||||
Values: VariableValues{
|
Values: VariableValues{
|
||||||
VariableValue{Platform: "linux", Value: "ffmpeg"},
|
VariableValue{Platform: "linux", Value: "ffmpeg"},
|
||||||
VariableValue{Platform: "windows", Value: "ffmpeg.exe"},
|
VariableValue{Platform: "windows", Value: "ffmpeg.exe"},
|
||||||
@ -68,7 +66,7 @@ var defaultConfig = Conf{
|
|||||||
},
|
},
|
||||||
// TODO: determine useful defaults for these.
|
// TODO: determine useful defaults for these.
|
||||||
// "job_storage": {
|
// "job_storage": {
|
||||||
// Direction: "twoway",
|
// IsTwoWay: true,
|
||||||
// Values: VariableValues{
|
// Values: VariableValues{
|
||||||
// VariableValue{Platform: "linux", Value: "/shared/flamenco/jobs"},
|
// VariableValue{Platform: "linux", Value: "/shared/flamenco/jobs"},
|
||||||
// VariableValue{Platform: "windows", Value: "S:/flamenco/jobs"},
|
// VariableValue{Platform: "windows", Value: "S:/flamenco/jobs"},
|
||||||
@ -76,7 +74,7 @@ var defaultConfig = Conf{
|
|||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
// "render": {
|
// "render": {
|
||||||
// Direction: "twoway",
|
// IsTwoWay: true,
|
||||||
// Values: VariableValues{
|
// Values: VariableValues{
|
||||||
// VariableValue{Platform: "linux", Value: "/shared/flamenco/render"},
|
// VariableValue{Platform: "linux", Value: "/shared/flamenco/render"},
|
||||||
// VariableValue{Platform: "windows", Value: "S:/flamenco/render"},
|
// VariableValue{Platform: "windows", Value: "S:/flamenco/render"},
|
||||||
|
@ -145,8 +145,7 @@ type Conf struct {
|
|||||||
|
|
||||||
// Variable defines a configuration variable.
|
// Variable defines a configuration variable.
|
||||||
type Variable struct {
|
type Variable struct {
|
||||||
// Either "oneway" or "twoway"
|
IsTwoWay bool `yaml:"is_twoway,omitempty" json:"is_twoway,omitempty"`
|
||||||
Direction string `yaml:"direction" json:"direction"`
|
|
||||||
// Mapping from variable value to audience/platform definition.
|
// Mapping from variable value to audience/platform definition.
|
||||||
Values VariableValues `yaml:"values" json:"values"`
|
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.
|
// Two-way values should not end in path separator.
|
||||||
// Given a variable 'apps' with value '/path/to/apps',
|
// Given a variable 'apps' with value '/path/to/apps',
|
||||||
// '/path/to/apps/blender' should be remapped to '{apps}/blender'.
|
// '/path/to/apps/blender' should be remapped to '{apps}/blender'.
|
||||||
if variable.Direction == "twoway" {
|
if variable.IsTwoWay {
|
||||||
if strings.Contains(value.Value, "\\") {
|
if strings.Contains(value.Value, "\\") {
|
||||||
log.Warn().
|
log.Warn().
|
||||||
Str("variable", name).
|
Str("variable", name).
|
||||||
@ -346,20 +345,7 @@ func (c *Conf) ExpandVariables(valueToExpand string, audience VariableAudience,
|
|||||||
// checkVariables performs some basic checks on variable definitions.
|
// checkVariables performs some basic checks on variable definitions.
|
||||||
// All errors are logged, not returned.
|
// All errors are logged, not returned.
|
||||||
func (c *Conf) checkVariables() {
|
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 {
|
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 {
|
for valueIndex, value := range variable.Values {
|
||||||
// No platforms at all.
|
// No platforms at all.
|
||||||
if value.Platform == "" && len(value.Platforms) == 0 {
|
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.TaskLogsPath, config.TaskLogsPath)
|
||||||
assert.Equal(t, defaultConfig.DatabaseDSN, config.DatabaseDSN)
|
assert.Equal(t, defaultConfig.DatabaseDSN, config.DatabaseDSN)
|
||||||
|
|
||||||
assert.Contains(t, config.Variables, "job_storage")
|
assert.Equal(t, false, config.Variables["ffmpeg"].IsTwoWay)
|
||||||
assert.Contains(t, config.Variables, "render")
|
|
||||||
assert.Equal(t, "oneway", config.Variables["ffmpeg"].Direction)
|
|
||||||
assert.Equal(t, "ffmpeg", config.Variables["ffmpeg"].Values[0].Value)
|
assert.Equal(t, "ffmpeg", config.Variables["ffmpeg"].Values[0].Value)
|
||||||
assert.Equal(t, "linux", config.Variables["ffmpeg"].Values[0].Platform)
|
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) {
|
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[0].Value, "/path/to/blender")
|
||||||
assert.Equal(t, c.Variables["blender"].Values[1].Value, "/valid/path/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…
x
Reference in New Issue
Block a user