feat: override all existing scale parameters when calling ps-set-scale

This commit is contained in:
Jose Diaz-Gonzalez committed 2021-08-01 16:20:19 -04:00
1 parent 5ad5a29a00
commit ef262c26e8
3 files changed
+17 -12

No files matched your search

+13 -8
View File
@@ -62,11 +62,11 @@ func extractOrGenerateScalefile(appName string, image string) error {
if common.FileExists(destination) { if common.FileExists(destination) {
common.LogInfo1Quiet("DOKKU_SCALE file exists") common.LogInfo1Quiet("DOKKU_SCALE file exists")
return updateScalefile(appName, make(map[string]int)) return updateScalefile(appName, false, make(map[string]int))
} }
common.LogInfo1Quiet("DOKKU_SCALE file not found in app image. Generating one based on Procfile...") common.LogInfo1Quiet("DOKKU_SCALE file not found in app image. Generating one based on Procfile...")
if err := updateScalefile(appName, make(map[string]int)); err != nil { if err := updateScalefile(appName, false, make(map[string]int)); err != nil {
common.LogDebug(fmt.Sprintf("Error generating scale file: %s", err.Error())) common.LogDebug(fmt.Sprintf("Error generating scale file: %s", err.Error()))
return err return err
} }
@@ -380,14 +380,14 @@ func scaleReport(appName string) error {
return nil return nil
} }
func scaleSet(appName string, skipDeploy bool, processTuples []string) error { func scaleSet(appName string, skipDeploy bool, clearExisting bool, processTuples []string) error {
scale, err := parseProcessTuples(processTuples) scale, err := parseProcessTuples(processTuples)
if err != nil { if err != nil {
return err return err
} }
common.LogInfo1(fmt.Sprintf("Scaling %s processes: %s", appName, strings.Join(processTuples, " "))) common.LogInfo1(fmt.Sprintf("Scaling %s processes: %s", appName, strings.Join(processTuples, " ")))
if err := updateScalefile(appName, scale); err != nil { if err := updateScalefile(appName, clearExisting, scale); err != nil {
return err return err
} }
@@ -407,22 +407,27 @@ func scaleSet(appName string, skipDeploy bool, processTuples []string) error {
return common.PlugnTrigger("release-and-deploy", []string{appName, imageTag}...) return common.PlugnTrigger("release-and-deploy", []string{appName, imageTag}...)
} }
func updateScalefile(appName string, scaleUpdates map[string]int) error { func updateScalefile(appName string, clearExisting bool, scaleUpdates map[string]int) error {
if !hasScaleFile(appName) { if !hasScaleFile(appName) {
if err := generateScalefile(appName); err != nil { if err := generateScalefile(appName); err != nil {
return err return err
} }
} }
scale, err := readScaleFile(appName) scale := make(map[string]int)
if err != nil { if !clearExisting {
return err var err error
scale, err = readScaleFile(appName)
if err != nil {
return err
}
} }
procfilePath := getProcfilePath(appName) procfilePath := getProcfilePath(appName)
procfileExists := hasProcfile(appName) procfileExists := hasProcfile(appName)
validProcessTypes := make(map[string]bool) validProcessTypes := make(map[string]bool)
if procfileExists { if procfileExists {
var err error
validProcessTypes, err = processesInProcfile(procfilePath) validProcessTypes, err = processesInProcfile(procfilePath)
if err != nil { if err != nil {
return err return err
+2 -2
View File
@@ -123,7 +123,7 @@ func CommandScale(appName string, skipDeploy bool, processTuples []string) error
procfilePath := getProcfilePath(appName) procfilePath := getProcfilePath(appName)
if !hasScaleFile(appName) || common.FileExists(procfilePath) { if !hasScaleFile(appName) || common.FileExists(procfilePath) {
update := func() error { update := func() error {
return updateScalefile(appName, make(map[string]int)) return updateScalefile(appName, false, make(map[string]int))
} }
if err := common.SuppressOutput(update); err != nil { if err := common.SuppressOutput(update); err != nil {
return err return err
@@ -138,7 +138,7 @@ func CommandScale(appName string, skipDeploy bool, processTuples []string) error
return fmt.Errorf("App %s contains DOKKU_SCALE file and cannot be manually scaled", appName) return fmt.Errorf("App %s contains DOKKU_SCALE file and cannot be manually scaled", appName)
} }
return scaleSet(appName, skipDeploy, processTuples) return scaleSet(appName, skipDeploy, false, processTuples)
} }
// CommandSet sets or clears a ps property for an app // CommandSet sets or clears a ps property for an app
+2 -2
View File
@@ -150,7 +150,7 @@ func TriggerPostCreate(appName string) error {
return err return err
} }
return updateScalefile(appName, make(map[string]int)) return updateScalefile(appName, false, make(map[string]int))
} }
// TriggerPostDelete destroys the ps properties for a given app container // TriggerPostDelete destroys the ps properties for a given app container
@@ -285,5 +285,5 @@ func TriggerPsCurrentScale(appName string) error {
// TriggerPsSetScale configures the scale parameters for a given app // TriggerPsSetScale configures the scale parameters for a given app
func TriggerPsSetScale(appName string, skipDeploy bool, processTuples []string) error { func TriggerPsSetScale(appName string, skipDeploy bool, processTuples []string) error {
return scaleSet(appName, skipDeploy, processTuples) return scaleSet(appName, skipDeploy, true, processTuples)
} }