diff --git a/devenv/db.go b/devenv/db.go index 52010a4c..7e0896b5 100644 --- a/devenv/db.go +++ b/devenv/db.go @@ -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 @@ -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 { diff --git a/server/app.go b/server/app.go index 8c5a2d06..3bfdf6ad 100644 --- a/server/app.go +++ b/server/app.go @@ -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) @@ -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()) diff --git a/terraform/run.go b/terraform/run.go index f059ebcc..e127f162 100644 --- a/terraform/run.go +++ b/terraform/run.go @@ -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) } @@ -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 }