-
Notifications
You must be signed in to change notification settings - Fork 288
/
configs_controller.go
64 lines (54 loc) · 1.49 KB
/
configs_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package engine
import (
"context"
"time"
"github.com/windmilleng/tilt/internal/store"
"github.com/windmilleng/tilt/internal/tiltfile"
)
type ConfigsController struct {
disabledForTesting bool
}
func NewConfigsController() *ConfigsController {
return &ConfigsController{}
}
func (cc *ConfigsController) DisableForTesting(disabled bool) {
cc.disabledForTesting = disabled
}
func (cc *ConfigsController) OnChange(ctx context.Context, st store.RStore) {
if cc.disabledForTesting {
return
}
state := st.RLockState()
defer st.RUnlockState()
initManifests := state.InitManifests
if len(state.PendingConfigFileChanges) == 0 {
return
}
filesChanged := make(map[string]bool)
for k, v := range state.PendingConfigFileChanges {
filesChanged[k] = v
}
// TODO(dbentley): there's a race condition where we start it before we clear it, so we could start many tiltfile reloads...
go func() {
startTime := time.Now()
st.Dispatch(ConfigsReloadStartedAction{FilesChanged: filesChanged})
matching := map[string]bool{}
for _, m := range initManifests {
matching[string(m)] = true
}
tiltfilePath, err := state.RelativeTiltfilePath()
if err != nil {
st.Dispatch(NewErrorAction(err))
return
}
manifests, globalYAML, configFiles, err := tiltfile.Load(ctx, tiltfilePath, matching)
st.Dispatch(ConfigsReloadedAction{
Manifests: manifests,
GlobalYAML: globalYAML,
ConfigFiles: configFiles,
StartTime: startTime,
FinishTime: time.Now(),
Err: err,
})
}()
}