Skip to content

Commit

Permalink
engine responds to invalidated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Oct 10, 2024
1 parent 879cb3d commit 436279f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions internal/buildengine/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ import (
"github.com/TBD54566975/ftl/internal/schema"
)

var invalidateDependenciesError = errors.New("dependencies need to be updated")

Check warning on line 20 in internal/buildengine/build.go

View workflow job for this annotation

GitHub Actions / Lint

error-naming: error var invalidateDependenciesError should have name of the form errFoo (revive)

// Build a module in the given directory given the schema and module config.
//
// A lock file is used to ensure that only one build is running at a time.
//
// Returns invalidateDependenciesError if the build failed due to a change in dependencies.
func build(ctx context.Context, plugin languageplugin.LanguagePlugin, projectRootDir string, bctx languageplugin.BuildContext, buildEnv []string, devMode bool) (moduleSchema *schema.Module, deploy []string, err error) {
logger := log.FromContext(ctx).Module(bctx.Config.Module).Scope("build")
ctx = log.ContextWithLogger(ctx, logger)
Expand All @@ -46,6 +50,10 @@ func handleBuildResult(ctx context.Context, c moduleconfig.ModuleConfig, eitherR
result = eitherResult.Get()
}

if result.InvalidateDependencies {
return nil, nil, invalidateDependenciesError
}

var errs []error
for _, e := range result.Errors {
if e.Level == builderrors.WARN {
Expand Down
10 changes: 9 additions & 1 deletion internal/buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ func (e *Engine) BuildAndDeploy(ctx context.Context, replicas int32, waitForDepl
type buildCallback func(ctx context.Context, module Module) error

func (e *Engine) buildWithCallback(ctx context.Context, callback buildCallback, moduleNames ...string) error {

if len(moduleNames) == 0 {
e.moduleMetas.Range(func(name string, meta moduleMeta) bool {
moduleNames = append(moduleNames, name)
Expand Down Expand Up @@ -820,6 +819,15 @@ func (e *Engine) build(ctx context.Context, moduleName string, builtModules map[
}, e.buildEnv, e.devMode)
if err != nil {
terminal.UpdateModuleState(ctx, moduleName, terminal.BuildStateFailed)
if errors.Is(err, invalidateDependenciesError) {
go func() {
logger := log.FromContext(ctx)
err := e.BuildAndDeploy(ctx, 1, true, moduleName)
e.reportBuildFailed(err)
terminal.UpdateModuleState(ctx, moduleName, terminal.BuildStateFailed)
logger.Errorf(err, "Build and deploy failed for module %q", moduleName)
}()
}
return err
}
// update files to deploy
Expand Down
2 changes: 1 addition & 1 deletion internal/buildengine/languageplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type BuildResult struct {
// Files to deploy, relative to the module config's DeployDir
Deploy []string

// Docs
// Whether the module needs to recalculate its dependencies
InvalidateDependencies bool
}

Expand Down

0 comments on commit 436279f

Please sign in to comment.