Skip to content

Commit

Permalink
fix: Unit type shouldn't be a variable
Browse files Browse the repository at this point in the history
Add a configurable longer delay when builds fail under `ftl dev` to
avoid hot loops.
  • Loading branch information
alecthomas committed Jan 15, 2024
1 parent aa4cb1d commit 0ea09c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions cmd/ftl/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ type moduleFolderInfo struct {
}

type devCmd struct {
BaseDir string `arg:"" help:"Directory to watch for FTL modules" type:"existingdir" default:"."`
Watch time.Duration `help:"Watch template directory at this frequency and regenerate on change." default:"500ms"`
modules map[string]moduleFolderInfo
client ftlv1connect.ControllerServiceClient
BaseDir string `arg:"" help:"Directory to watch for FTL modules" type:"existingdir" default:"."`
Watch time.Duration `help:"Watch template directory at this frequency and regenerate on change." default:"500ms"`
FailureDelay time.Duration `help:"Delay before retrying a failed deploy." default:"5s"`
modules map[string]moduleFolderInfo
client ftlv1connect.ControllerServiceClient
}

func (d *devCmd) Run(ctx context.Context, client ftlv1connect.ControllerServiceClient) error {
Expand All @@ -40,6 +41,7 @@ func (d *devCmd) Run(ctx context.Context, client ftlv1connect.ControllerServiceC

lastScanTime := time.Now()
for {
delay := d.Watch
iterationStartTime := time.Now()

tomls, err := d.getTomls(ctx)
Expand All @@ -65,13 +67,15 @@ func (d *devCmd) Run(ctx context.Context, client ftlv1connect.ControllerServiceC
if err != nil {
logger.Errorf(err, "Error deploying module %s. Will retry", dir)
delete(d.modules, dir)
// Increase delay when there's a compile failure.
delay = d.FailureDelay
}
}
}

lastScanTime = iterationStartTime
select {
case <-time.After(d.Watch):
case <-time.After(delay):
case <-ctx.Done():
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion go-runtime/sdk/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
//
// It can be used as a parameter or return value to indicate that a function
// does not accept or return any value.
var Unit = DataRef{Module: "builtin", Name: "Unit"}
type Unit struct{}

// Ref is an untyped reference to a symbol.
type Ref struct {
Expand Down

0 comments on commit 0ea09c3

Please sign in to comment.