Skip to content

Commit

Permalink
remove remaining terminal usage in engine
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Oct 22, 2024
1 parent 95f6724 commit 85f3bbf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
30 changes: 15 additions & 15 deletions internal/buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/TBD54566975/ftl/internal/rpc"
"github.com/TBD54566975/ftl/internal/schema"
"github.com/TBD54566975/ftl/internal/slices"
"github.com/TBD54566975/ftl/internal/terminal"
"github.com/TBD54566975/ftl/internal/watch"
)

Expand Down Expand Up @@ -106,6 +105,14 @@ type ModuleRemoved struct {
func (ModuleRemoved) buildEvent() {}
func (ModuleRemoved) rawBuildEvent() {}

// ModuleBuildWaiting is published when a build is waiting for dependencies to build
type ModuleBuildWaiting struct {
Config moduleconfig.ModuleConfig
}

func (ModuleBuildWaiting) buildEvent() {}
func (ModuleBuildWaiting) rawBuildEvent() {}

// ModuleBuildStarted is published when a build has started for a module.
type ModuleBuildStarted struct {
Config moduleconfig.ModuleConfig
Expand Down Expand Up @@ -642,6 +649,8 @@ func (e *Engine) watchForEventsToPublish(ctx context.Context) {
delete(moduleErrors, event.Module)
delete(explicitlyBuilding, event.Module)
delete(autoRebuilding, event.Module)
case ModuleBuildWaiting:

case ModuleBuildStarted:
if isIdle {
isIdle = false
Expand Down Expand Up @@ -732,8 +741,6 @@ func (e *Engine) BuildAndDeploy(ctx context.Context, replicas int32, waitForDepl
return e.buildWithCallback(ctx, func(buildCtx context.Context, module Module) error {
buildGroup.Go(func() error {
e.modulesToBuild.Store(module.Config.Module, false)
terminal.UpdateModuleState(ctx, module.Config.Module, terminal.BuildStateDeploying)

e.rawEngineUpdates <- ModuleDeployStarted{Module: module.Config.Module}
err := Deploy(buildCtx, module, module.Deploy, replicas, waitForDeployOnline, e.client)
if err != nil {
Expand Down Expand Up @@ -776,7 +783,7 @@ func (e *Engine) buildWithCallback(ctx context.Context, callback buildCallback,
})
}

mustBuildChan := make(chan string, len(moduleNames))
mustBuildChan := make(chan moduleconfig.ModuleConfig, len(moduleNames))
wg := errgroup.Group{}
for _, name := range moduleNames {
wg.Go(func() error {
Expand All @@ -791,7 +798,7 @@ func (e *Engine) buildWithCallback(ctx context.Context, callback buildCallback,
}

e.moduleMetas.Store(name, meta)
mustBuildChan <- name
mustBuildChan <- meta.module.Config
return nil
})
}
Expand All @@ -800,10 +807,9 @@ func (e *Engine) buildWithCallback(ctx context.Context, callback buildCallback,
}
close(mustBuildChan)
mustBuild := map[string]bool{}
for name := range mustBuildChan {
mustBuild[name] = true

terminal.UpdateModuleState(ctx, name, terminal.BuildStateWaiting)
for config := range mustBuildChan {
mustBuild[config.Module] = true
e.rawEngineUpdates <- ModuleBuildWaiting{Config: config}
}

graph, err := e.Graph(moduleNames...)
Expand Down Expand Up @@ -847,7 +853,6 @@ func (e *Engine) buildWithCallback(ctx context.Context, callback buildCallback,
ctx := log.ContextWithLogger(ctx, logger)
err := e.tryBuild(ctx, mustBuild, moduleName, builtModules, schemas, callback)
if err != nil {
terminal.UpdateModuleState(ctx, moduleName, terminal.BuildStateFailed)
errCh <- err
}
return nil
Expand Down Expand Up @@ -941,10 +946,8 @@ func (e *Engine) mustSchema(ctx context.Context, moduleName string, builtModules
//
// Assumes that all dependencies have been built and are available in "built".
func (e *Engine) build(ctx context.Context, moduleName string, builtModules map[string]*schema.Module, schemas chan<- *schema.Module) error {
terminal.UpdateModuleState(ctx, moduleName, terminal.BuildStateBuilding)
meta, ok := e.moduleMetas.Load(moduleName)
if !ok {
terminal.UpdateModuleState(ctx, moduleName, terminal.BuildStateFailed)
return fmt.Errorf("module %q not found", moduleName)
}

Expand All @@ -956,7 +959,6 @@ func (e *Engine) build(ctx context.Context, moduleName string, builtModules map[
Dependencies: meta.module.Dependencies(Raw),
}, e.buildEnv, e.devMode)
if err != nil {
terminal.UpdateModuleState(ctx, moduleName, terminal.BuildStateFailed)
// TODO: handle errInvalidateDependencies
return err
}
Expand All @@ -968,8 +970,6 @@ func (e *Engine) build(ctx context.Context, moduleName string, builtModules map[
meta.module = meta.module.CopyWithDeploy(deploy)
return meta, false
})

terminal.UpdateModuleState(ctx, moduleName, terminal.BuildStateBuilt)
schemas <- moduleSchema
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions internal/buildengine/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func updateTerminalWithEngineEvents(ctx context.Context, topic *pubsub.Topic[Eng
case ModuleRemoved:
terminal.UpdateModuleState(ctx, event.Module, terminal.BuildStateTerminated)

case ModuleBuildWaiting:
terminal.UpdateModuleState(ctx, event.Config.Module, terminal.BuildStateWaiting)
case ModuleBuildStarted:
terminal.UpdateModuleState(ctx, event.Config.Module, terminal.BuildStateBuilding)
case ModuleBuildSuccess:
Expand Down
4 changes: 2 additions & 2 deletions internal/lsp/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (s *Server) Subscribe(ctx context.Context, topic *pubsub.Topic[buildengine.
})

case buildengine.ModuleBuildSuccess, buildengine.ModuleBuildFailed, buildengine.ModuleAdded,
buildengine.ModuleRemoved, buildengine.ModuleDeployStarted, buildengine.ModuleDeploySuccess,
buildengine.ModuleDeployFailed:
buildengine.ModuleRemoved, buildengine.ModuleBuildWaiting, buildengine.ModuleDeployStarted,
buildengine.ModuleDeploySuccess, buildengine.ModuleDeployFailed:
}
}
}
Expand Down

0 comments on commit 85f3bbf

Please sign in to comment.