Skip to content

Commit

Permalink
check: make maxRenderTime configurable (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
matslina authored Apr 29, 2024
1 parent f4d5078 commit 0d1fdc4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import (
"tidbyt.dev/pixlet/tools"
)

const MaxRenderTime = 1000000000 // 1000ms
var maxRenderTime = time.Duration(1 * time.Second)

func init() {
CheckCmd.Flags().BoolVarP(&rflag, "recursive", "r", false, "find apps recursively")
CheckCmd.Flags().DurationVarP(&maxRenderTime, "max-render-time", "", maxRenderTime, "override the default max render time")
}

var CheckCmd = &cobra.Command{
Use: "check <path>...",
Expand Down Expand Up @@ -114,12 +119,12 @@ func checkCmd(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("could not profile app: %w", err)
}
if p.DurationNanos > MaxRenderTime {
if p.DurationNanos > maxRenderTime.Nanoseconds() {
foundIssue = true
failure(
path,
fmt.Errorf("app takes too long to render %s", time.Duration(p.DurationNanos)),
fmt.Sprintf("try optimizing your app using `pixlet profile %s` to get it under %s", path, time.Duration(MaxRenderTime)),
fmt.Sprintf("try optimizing your app using `pixlet profile %s` to get it under %s", path, time.Duration(maxRenderTime)),
)
continue
}
Expand Down

0 comments on commit 0d1fdc4

Please sign in to comment.