Skip to content

Commit

Permalink
Mark envs as processed
Browse files Browse the repository at this point in the history
  • Loading branch information
alephnull committed Nov 23, 2020
1 parent 91ca8c4 commit c067624
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions devenv/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
NAME = "name"
// NEW is the state when an env is new
NEW = "new"
// PROCESSED is the state when an env has been processed by the runner
PROCESSED = "processed"
)

// DevEnv is a tyk env on the dev env. This is not a type because
Expand Down Expand Up @@ -261,8 +263,6 @@ func InsertEnv(db dynamodbiface.ClientAPI, table string, env string, stateMap De
func UpsertEnv(db dynamodbiface.ClientAPI, table string, env string, stateMap DevEnv) error {
// Remove key elements from the map as updates will fail
delete(stateMap, NAME)
// Reset the state so that the runner will pick it up
stateMap[STATE] = NEW

update := expression.UpdateBuilder{}
for k, v := range stateMap {
Expand Down
4 changes: 3 additions & 1 deletion server/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ func (a *App) newBuild(w http.ResponseWriter, r *http.Request) {
ecrState[repo] = sha
log.Trace().Interface("ecrState", ecrState).Msgf("for ref %s after update", ref)

// Set state so that the runner will pick this up
ecrState[devenv.STATE] = devenv.NEW
err = devenv.UpsertEnv(a.DB, a.Env.TableName, ref, ecrState)
if err != nil {
util.StatCount("newbuild.failures", 1)
Expand Down Expand Up @@ -256,7 +258,7 @@ func (a *App) updateEnv(w http.ResponseWriter, r *http.Request) {
}
log.Debug().Interface("env", newEnv).Msgf("update for %s received", env)

err = devenv.UpsertEnv(a.DB, a.Env.TableName, vars["name"], newEnv)
err = devenv.UpsertEnv(a.DB, a.Env.TableName, env, newEnv)
if err != nil {
if ierr, ok := err.(devenv.ExistsError); ok {
respondWithError(w, http.StatusConflict, ierr.Error())
Expand Down
9 changes: 8 additions & 1 deletion terraform/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ func Run(cfg aws.Config, confPath string) error {
log.Fatal().Err(err).Msg("unable to setup terraform creds")
}

envs, err := devenv.GetNewEnvs(dynamodb.New(cfg), e.TableName, e.Repos)
db := dynamodb.New(cfg)
envs, err := devenv.GetNewEnvs(db, e.TableName, e.Repos)
if err != nil {
log.Fatal().Err(err).Msgf("could not get new envs from table %s", e.TableName)
}
Expand Down Expand Up @@ -200,6 +201,12 @@ func Run(cfg aws.Config, confPath string) error {
lastError = err
continue
}
// Mark env processed so that the runner will not pick it up
env[devenv.STATE] = devenv.PROCESSED
err = devenv.UpsertEnv(db, e.TableName, envName, env)
if err != nil {
log.Error().Err(err).Str("env", envName).Msg("could not mark env as PROCESSED")
}
}
return lastError
}

0 comments on commit c067624

Please sign in to comment.