feat: add ability to increase the max parallelism when deploying a given process type

This commit is contained in:
Jose Diaz-Gonzalez
2021-10-09 19:41:06 -04:00
parent 904894722f
commit 55554ce9bd
12 changed files with 97 additions and 12 deletions

View File

@@ -6,3 +6,4 @@
/subcommands/*
/triggers
/triggers/*
/app-json-process-deploy-parallelism

View File

@@ -1,5 +1,5 @@
SUBCOMMANDS = subcommands/report subcommands/set
TRIGGERS = triggers/install triggers/post-delete triggers/post-deploy triggers/pre-deploy triggers/report
TRIGGERS = triggers/app-json-process-deploy-parallelism triggers/install triggers/post-delete triggers/post-deploy triggers/pre-deploy triggers/report
BUILD = commands subcommands triggers
PLUGIN_NAME = app-json

View File

@@ -39,7 +39,8 @@ type CronCommand struct {
// Formation is a struct that represents the scale for a process from an app.json file
type Formation struct {
Quantity int `json:"quantity"`
Quantity *int `json:"quantity"`
MaxParallel *int `json:"max_parallel"`
}
// GetAppjsonDirectory returns the directory containing a given app's extracted app.json file

View File

@@ -500,7 +500,9 @@ func setScale(appName string, image string) error {
clearExisting := false
args := []string{appName, strconv.FormatBool(skipDeploy), strconv.FormatBool(clearExisting)}
for processType, formation := range appJSON.Formation {
args = append(args, fmt.Sprintf("%s=%d", processType, formation.Quantity))
if formation.Quantity != nil {
args = append(args, fmt.Sprintf("%s=%d", processType, *formation.Quantity))
}
}
if len(args) == 3 {
@@ -567,7 +569,7 @@ func injectDokkuScale(appName string, image string) error {
}
appJSON.Formation[processType] = Formation{
Quantity: quantity,
Quantity: &quantity,
}
}

View File

@@ -18,6 +18,10 @@ func main() {
var err error
switch trigger {
case "app-json-process-deploy-parallelism":
appName := flag.Arg(0)
processType := flag.Arg(1)
err = appjson.TriggerAppJSONProcessDeployParallelism(appName, processType)
case "install":
err = appjson.TriggerInstall()
case "post-delete":

View File

@@ -8,6 +8,32 @@ import (
"github.com/dokku/dokku/plugins/common"
)
// TriggerAppJSONProcessDeployParallelism returns the max number of processes to deploy in parallel
func TriggerAppJSONProcessDeployParallelism(appName string, processType string) error {
appJSON, err := getAppJSON(appName)
if err != nil {
return err
}
parallelism := 1
for procType, formation := range appJSON.Formation {
if procType != processType {
continue
}
if formation.MaxParallel == nil {
continue
}
if *formation.MaxParallel > 0 {
parallelism = *formation.MaxParallel
}
}
fmt.Println(parallelism)
return nil
}
// TriggerInstall initializes app restart policies
func TriggerInstall() error {
if err := common.PropertySetup("app-json"); err != nil {