Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use communication channel to notify about the websocket closed #131

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions server/events/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