Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
some tweaks for stability of async render
Browse files Browse the repository at this point in the history
  • Loading branch information
dexhorthy committed Aug 14, 2018
1 parent 670864d commit 7aa425e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
39 changes: 23 additions & 16 deletions pkg/lifecycle/daemon/routes_navcycle_completestep.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/replicatedhq/ship/pkg/api"
"github.com/replicatedhq/ship/pkg/lifecycle/daemon/daemontypes"
"github.com/replicatedhq/ship/pkg/lifecycle/daemon/statusonly"
"github.com/replicatedhq/ship/pkg/state"
)

func (d *NavcycleRoutes) completeStep(c *gin.Context) {
Expand All @@ -37,44 +38,50 @@ func (d *NavcycleRoutes) completeStep(c *gin.Context) {
return
}

err := d.StepExecutor(d, step)
err = d.handleSyncStep(err, debug, step, stepID)
currentState, err := d.StateManager.TryLoad()
if err != nil {
level.Error(d.Logger).Log("event", "sync.fail", "error", err)
c.AbortWithError(500, err)
return
}

errChan := make(chan error)
d.StepProgress.Store(stepID, daemontypes.JSONProgress("v2router", map[string]interface{}{
"status": "working",
}))
go func() {
errChan <- d.StepExecutor(d, step)
}()

// hack, give it 10 ms in case its an instant step. Hydrate and send will read progress from the syncMap
time.Sleep(10 * time.Millisecond)

d.hydrateAndSend(daemontypes.NewStep(step), c)
go d.handleAsync(errChan, debug, step, stepID, currentState)
return
}

d.errNotFond(c)
}

func (d *NavcycleRoutes) handleSyncStep(err error, debug log.Logger, step api.Step, stepID string) error {
func (d *NavcycleRoutes) handleAsync(errChan chan error, debug log.Logger, step api.Step, stepID string, state state.State) {
err := d.awaitAsyncStep(errChan, debug, step)
if err != nil {
debug.Log("event", "execute.fail", "err", err)
d.StepProgress.Store(stepID, daemontypes.JSONProgress("v2router", map[string]interface{}{
"status": fmt.Sprintf("failed - %v", err),
}))
return errors.Wrap(err, "execute step")
}
currentState, err := d.StateManager.TryLoad()
if err != nil {
return errors.Wrap(err, "load state")
return
}

newState := currentState.Versioned().WithCompletedStep(step)
newState := state.Versioned().WithCompletedStep(step)
err = d.StateManager.Save(newState)
if err != nil {
level.Error(debug).Log("event", "state.save.fail", "err", err)
return errors.Wrap(err, "save state")
level.Error(d.Logger).Log("event", "state.save.fail", "err", err, "step.id", stepID)
return
}

d.StepProgress.Store(stepID, daemontypes.JSONProgress("v2router", map[string]interface{}{
"status": "success",
}))
// HAAAACK
time.Sleep(1 * time.Second)
return nil
}

func (d *NavcycleRoutes) awaitAsyncStep(errChan chan error, debug log.Logger, step api.Step) error {
Expand Down
3 changes: 1 addition & 2 deletions pkg/specs/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ var (
{
KustomizeIntro: &api.KustomizeIntro{
StepShared: api.StepShared{
ID: "kustomize-intro",
Requires: []string{"render"},
ID: "kustomize-intro",
},
},
},
Expand Down

0 comments on commit 7aa425e

Please sign in to comment.