Skip to content

Commit

Permalink
Merge pull request #65 from zhihaoy/wait-before-deploy
Browse files Browse the repository at this point in the history
Wait until update finishes before deploying an image
  • Loading branch information
nelhage authored Feb 17, 2023
2 parents 9366cd0 + a0fe7c2 commit a0e264e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/llama/internal/function/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func createOrUpdateFunction(ctx context.Context, g *cli.GlobalState, cfg *functi

_, err := client.CreateFunction(args)
if err == nil {
return waitForFunction(ctx, client, cfg)
return waitForFunction(ctx, client, cfg, "Creating")
}
if reqerr, ok := err.(awserr.RequestFailure); ok && reqerr.StatusCode() == 409 {
return updateFunction(ctx, g, cfg)
Expand Down Expand Up @@ -95,6 +95,9 @@ func updateFunction(ctx context.Context, g *cli.GlobalState, cfg *functionConfig
if _, err := client.UpdateFunctionConfiguration(args); err != nil {
return err
}
if err := waitForFunction(ctx, client, cfg, "Updating"); err != nil {
return err
}

if cfg.tag != "" {
codeArgs := &lambda.UpdateFunctionCodeInput{
Expand All @@ -104,14 +107,15 @@ func updateFunction(ctx context.Context, g *cli.GlobalState, cfg *functionConfig
if _, err := client.UpdateFunctionCode(codeArgs); err != nil {
return err
}

return waitForFunction(ctx, client, cfg, "Deploying")
}
return waitForFunction(ctx, client, cfg)

return nil
}

func waitForFunction(ctx context.Context, client *lambda.Lambda, config *functionConfig) error {
func waitForFunction(ctx context.Context, client *lambda.Lambda, config *functionConfig, prompt string) error {
args := &lambda.GetFunctionInput{FunctionName: &config.name}
log.Printf("Update complete, waiting for function %s...", config.name)
log.Printf("%s function %s...", prompt, config.name)
for {
time.Sleep(3 * time.Second)
out, err := client.GetFunction(args)
Expand Down

0 comments on commit a0e264e

Please sign in to comment.