Skip to content

Commit

Permalink
Move revlink warmup into runPlanModel to not show hanging spinner bef…
Browse files Browse the repository at this point in the history
…ore the plan kicks off
  • Loading branch information
DavidS-ovm committed May 23, 2024
1 parent edcf34a commit 292bfc3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
16 changes: 13 additions & 3 deletions cmd/tea_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type runPlanModel struct {
args []string
planFile string

revlinkTask revlinkWarmupModel
taskModel
}
type runPlanNowMsg struct{}
Expand All @@ -32,12 +33,16 @@ func NewRunPlanModel(args []string, planFile string) runPlanModel {
args: args,
planFile: planFile,

taskModel: NewTaskModel("Planning Changes"),
revlinkTask: NewRevlinkWarmupModel(),
taskModel: NewTaskModel("Planning Changes"),
}
}

func (m runPlanModel) Init() tea.Cmd {
return nil
return tea.Batch(
m.revlinkTask.Init(),
m.taskModel.Init(),
)
}

func (m runPlanModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
Expand Down Expand Up @@ -94,8 +99,12 @@ func (m runPlanModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// propagate commands to components
// m.taskModel, cmd = m.taskModel.Update(msg)
// cmds = append(cmds, cmd)

}

var cmd tea.Cmd
m.revlinkTask, cmd = m.revlinkTask.Update(msg)
cmds = append(cmds, cmd)

return m, tea.Batch(cmds...)
}

Expand All @@ -111,6 +120,7 @@ func (m runPlanModel) View() string {
))
case taskStatusDone:
bits = append(bits, m.taskModel.View())
bits = append(bits, m.revlinkTask.View())
case taskStatusError, taskStatusSkipped:
// handled by caller
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tea_revlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type revlinkWarmupModel struct {
currentStatus *sdp.RevlinkWarmupResponse
}

func NewRevlinkWarmupModel() tea.Model {
func NewRevlinkWarmupModel() revlinkWarmupModel {
return revlinkWarmupModel{
taskModel: NewTaskModel("Discover and link all resources"),
status: make(chan *sdp.RevlinkWarmupResponse),
Expand All @@ -45,7 +45,7 @@ func (m revlinkWarmupModel) Init() tea.Cmd {
return m.taskModel.Init()
}

func (m revlinkWarmupModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m revlinkWarmupModel) Update(msg tea.Msg) (revlinkWarmupModel, tea.Cmd) {
cmds := []tea.Cmd{}

switch msg := msg.(type) {
Expand Down
4 changes: 0 additions & 4 deletions cmd/tea_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (m cmdModel) Init() tea.Cmd {
if viper.GetString("ovm-test-fake") != "" {
// don't init sources on test-fake runs
// m.tasks["02_config"] = NewInitialiseSourcesModel()
m.tasks["03_revlink"] = NewRevlinkWarmupModel()
return tea.Batch(
waitForCancellation(m.ctx, m.cancel),
m.tasks["00_oi"].Init(),
Expand All @@ -72,21 +71,18 @@ func (m cmdModel) Init() tea.Cmd {
time.Sleep(3 * time.Second)
return sourcesInitialisedMsg{}
},
m.tasks["03_revlink"].Init(),
m.cmd.Init(),
)
}

// these wait for taking a ctx until timeout and token are attached
m.tasks["02_config"] = NewInitialiseSourcesModel()
m.tasks["03_revlink"] = NewRevlinkWarmupModel()

return tea.Batch(
waitForCancellation(m.ctx, m.cancel),
m.tasks["00_oi"].Init(),
m.tasks["01_token"].Init(),
m.tasks["02_config"].Init(),
m.tasks["03_revlink"].Init(),
m.cmd.Init(),
)
}
Expand Down

0 comments on commit 292bfc3

Please sign in to comment.