Skip to content

Commit

Permalink
Performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-przybyl-wttech committed Jan 26, 2024
1 parent 4340256 commit 2d1fbf5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion examples/aws_ssm/aem.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ resource "aem_instance" "single" {
"sh aemw osgi config save --pid 'org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet' --input-string 'alias: /crx/server'",
"sh aemw repl agent setup -A --location 'author' --name 'publish' --input-string '{enabled: true, transportUri: \"http://localhost:4503/bin/receive?sling:authRequestLogin=1\", transportUser: admin, transportPassword: admin, userId: admin}'",
"sh aemw package deploy --file 'aem/home/lib/aem-service-pkg-6.5.*.0.zip'",
"invalid-command"
]
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/client/client_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func (c ClientManager) connection(typeName string, settings map[string]string) (
instanceID: settings["instance_id"],
region: settings["region"],
outputTimeout: cast.ToDuration(settings["output_timeout"]),
minWaitDelay: cast.ToDuration(settings["min_wait_delay"]),
maxWaitDelay: cast.ToDuration(settings["max_wait_delay"]),
context: context.Background(),
}, nil
}
Expand Down
30 changes: 21 additions & 9 deletions internal/client/connection_aws_ssm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type AWSSSMConnection struct {
instanceID string
region string
outputTimeout time.Duration
minWaitDelay time.Duration
maxWaitDelay time.Duration
client *ssm.Client
sessionId *string
context context.Context
Expand All @@ -39,7 +41,13 @@ func (a *AWSSSMConnection) User() string {

func (a *AWSSSMConnection) Connect() error {
if a.outputTimeout == 0 {
a.outputTimeout = time.Hour
a.outputTimeout = 5 * time.Hour
}
if a.minWaitDelay == 0 {
a.minWaitDelay = 5 * time.Millisecond
}
if a.maxWaitDelay == 0 {
a.maxWaitDelay = 5 * time.Second
}

var optFns []func(*config.LoadOptions) error
Expand Down Expand Up @@ -97,15 +105,19 @@ func (a *AWSSSMConnection) Command(cmdLine []string) ([]byte, error) {
CommandId: commandId,
InstanceId: aws.String(a.instanceID),
}
waiter := ssm.NewCommandExecutedWaiter(a.client)
_, err = waiter.WaitForOutput(a.context, invocationIn, a.outputTimeout)
optFns := []func(opt *ssm.CommandExecutedWaiterOptions){func(opt *ssm.CommandExecutedWaiterOptions) {
opt.MinDelay = a.minWaitDelay
opt.MaxDelay = a.maxWaitDelay
}}
waiter := ssm.NewCommandExecutedWaiter(a.client, optFns...)
invocationOut, err := waiter.WaitForOutput(a.context, invocationIn, a.outputTimeout)
if err != nil {
return nil, fmt.Errorf("ssm: error executing command: %v", err)
}

invocationOut, err := a.client.GetCommandInvocation(a.context, invocationIn)
if err != nil {
return nil, fmt.Errorf("ssm: error executing command: %v", err)
invocationOut, err = a.client.GetCommandInvocation(a.context, invocationIn)
if invocationOut != nil {
return nil, fmt.Errorf("ssm: error executing command: %v", *invocationOut.StandardErrorContent)
} else if err != nil {
return nil, fmt.Errorf("ssm: error executing command: %v", err)
}
}

return []byte(*invocationOut.StandardOutputContent), nil
Expand Down

0 comments on commit 2d1fbf5

Please sign in to comment.