Skip to content

Commit

Permalink
Merge branch 'main' into worstell/20240404-kotlin-ls-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
worstell authored Apr 5, 2024
2 parents 241e039 + 9d33f3a commit ac5ffa6
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,28 @@ func (e *Engine) Deploy(ctx context.Context, replicas int32, waitForDeployOnline

// Dev builds and deploys all local modules and watches for changes, redeploying as necessary.
func (e *Engine) Dev(ctx context.Context, period time.Duration) error {
return e.watchForModuleChanges(ctx, period)
}

func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration) error {
logger := log.FromContext(ctx)

schemaChanges := make(chan schemaChange, 128)
e.schemaChanges.Subscribe(schemaChanges)
defer e.schemaChanges.Unsubscribe(schemaChanges)

watchEvents := make(chan WatchEvent, 128)
watch := Watch(ctx, period, e.moduleDirs, e.externalDirs)
watch.Subscribe(watchEvents)
defer watch.Unsubscribe(watchEvents)
defer watch.Close()

// Build and deploy all modules first.
err := e.buildAndDeploy(ctx, 1, true)
if err != nil {
logger.Errorf(err, "initial deploy failed")
}

logger.Infof("All modules deployed, watching for changes...")

// Then watch for changes and redeploy.
return e.watchForModuleChanges(ctx, period)
}

func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration) error {
logger := log.FromContext(ctx)

moduleHashes := map[string][]byte{}
e.controllerSchema.Range(func(name string, sch *schema.Module) bool {
hash, err := computeModuleHash(sch)
Expand All @@ -235,16 +240,6 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
return true
})

schemaChanges := make(chan schemaChange, 128)
e.schemaChanges.Subscribe(schemaChanges)
defer e.schemaChanges.Unsubscribe(schemaChanges)

watchEvents := make(chan WatchEvent, 128)
watch := Watch(ctx, period, e.moduleDirs, e.externalDirs)
watch.Subscribe(watchEvents)
defer watch.Unsubscribe(watchEvents)
defer watch.Close()

// Watch for file and schema changes
for {
select {
Expand Down

0 comments on commit ac5ffa6

Please sign in to comment.