Skip to content

Commit

Permalink
Use communication channel to notify about the websocket closed (#131)
Browse files Browse the repository at this point in the history
* So for whatever reason tf show with big plan doesn't work in async

* rename isValidCommand to isAsyncEligibleCommand
  • Loading branch information
msarvar committed Oct 18, 2021
1 parent aeaab43 commit a69f2f1
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions server/core/terraform/terraform_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ func (c *DefaultClient) RunCommandWithVersion(ctx models.ProjectCommandContext,
}

// if the feature is enabled, we use the async workflow else we default to the original sync workflow
if shouldAllocate {
// Don't stream terraform show output to outCh
if shouldAllocate && isAsyncEligibleCommand(args[0]) {
_, outCh := c.RunCommandAsync(ctx, path, args, customEnvVars, v, workspace)
var lines []string
var err error
Expand Down Expand Up @@ -442,30 +443,21 @@ func (c *DefaultClient) RunCommandAsync(ctx models.ProjectCommandContext, path s

// Asynchronously copy from stdout/err to outCh.
go func() {
// Don't stream terraform show output to outCh
cmds := strings.Split(tfCmd, " ")
if isValidCommand(cmds[1]) {
c.projectCmdOutputHandler.Send(ctx, fmt.Sprintf("\n----- running terraform %s -----", args[0]))
}
c.projectCmdOutputHandler.Send(ctx, fmt.Sprintf("\n----- running terraform %s -----", args[0]))
s := bufio.NewScanner(stdout)
for s.Scan() {
message := s.Text()
outCh <- Line{Line: message}
if isValidCommand(cmds[1]) {
c.projectCmdOutputHandler.Send(ctx, "\t"+message)
}
c.projectCmdOutputHandler.Send(ctx, "\t"+message)
}
wg.Done()
}()
go func() {
cmds := strings.Split(tfCmd, " ")
s := bufio.NewScanner(stderr)
for s.Scan() {
message := s.Text()
outCh <- Line{Line: message}
if isValidCommand(cmds[1]) {
c.projectCmdOutputHandler.Send(ctx, message)
}
c.projectCmdOutputHandler.Send(ctx, message)
}
wg.Done()
}()
Expand Down Expand Up @@ -568,7 +560,7 @@ func generateRCFile(tfeToken string, tfeHostname string, home string) error {
return nil
}

func isValidCommand(cmd string) bool {
func isAsyncEligibleCommand(cmd string) bool {
for _, validCmd := range LogStreamingValidCmds {
if validCmd == cmd {
return true
Expand Down

0 comments on commit a69f2f1

Please sign in to comment.