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

fix(triggers): Updating playwright Engine lib execution #3933

Merged
merged 1 commit into from
Jul 15, 2024
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
18 changes: 12 additions & 6 deletions agent/workers/trigger/playwrightengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"time"
)

var (
Expand Down Expand Up @@ -45,7 +46,7 @@ func (te *playwrightTriggerer) Trigger(ctx context.Context, triggerConfig Trigge
return response, err
}

out, err := start(opts.TraceID.String(), opts.SpanID.String(), triggerConfig.PlaywrightEngine.Target, triggerConfig.PlaywrightEngine.Method, scriptPath)
out, err := start(ctx, opts.TraceID.String(), opts.SpanID.String(), triggerConfig.PlaywrightEngine.Target, triggerConfig.PlaywrightEngine.Method, scriptPath)
os.Remove(scriptPath)
if err != nil {
return response, err
Expand Down Expand Up @@ -76,14 +77,15 @@ func validate() error {
return nil
}

func start(traceId, spanId, url, method, scriptPath string) (string, error) {
func start(ctx context.Context, traceId, spanId, url, method, scriptPath string) (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}

if os.Getenv("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD") != "1" {
res, err := execCommand(
ctx,
app,
"playwright",
"install",
Expand All @@ -100,6 +102,7 @@ func start(traceId, spanId, url, method, scriptPath string) (string, error) {
}

res, err := execCommand(
ctx,
app,
"--yes",
libName,
Expand All @@ -121,17 +124,20 @@ func start(traceId, spanId, url, method, scriptPath string) (string, error) {
return res, nil
}

func execCommand(name string, args ...string) (string, error) {
cmd := exec.Command(name, args...)
func execCommand(ctx context.Context, name string, args ...string) (string, error) {
ctx, cancel := context.WithTimeout(ctx, time.Minute*3) //3 minutes
defer cancel()
cmd := exec.CommandContext(ctx, name, args...)

var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()

err := cmd.Run()
if err != nil {
return fmt.Sprint(err) + ": " + stderr.String(), err
res := fmt.Sprint(err) + ": " + out.String() + stderr.String()
return res, err
}

return out.String(), nil
Expand Down
Loading