Skip to content

Commit

Permalink
fix(api): clear cache wm after import (#3817)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault authored and sguiheux committed Jan 7, 2019
1 parent 37cabfc commit b88f80e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion engine/api/worker/model_import.go
Expand Up @@ -6,14 +6,15 @@ import (
"github.com/go-gorp/gorp"
"github.com/lib/pq"

"github.com/ovh/cds/engine/api/cache"
"github.com/ovh/cds/engine/api/database/gorpmapping"
"github.com/ovh/cds/engine/api/group"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/exportentities"
)

// ParseAndImport parse and import an exportentities.WorkerModel
func ParseAndImport(db gorp.SqlExecutor, eWorkerModel *exportentities.WorkerModel, force bool, u *sdk.User) (*sdk.Model, error) {
func ParseAndImport(db gorp.SqlExecutor, store cache.Store, eWorkerModel *exportentities.WorkerModel, force bool, u *sdk.User) (*sdk.Model, error) {
sdkWm, err := eWorkerModel.GetWorkerModel()
if err != nil {
return nil, err
Expand Down Expand Up @@ -131,5 +132,7 @@ currentUGroup:
return nil, sdk.WrapError(errAdd, "cannot add worker model %s", sdkWm.Name)
}

// delete current cache of worker model after import
store.DeleteAll(cache.Key("api:workermodels:*"))
return &sdkWm, nil
}
4 changes: 2 additions & 2 deletions engine/api/worker_model_import.go
Expand Up @@ -44,7 +44,7 @@ func (api *API) postWorkerModelImportHandler() service.Handler {
return sdk.WrapError(sdk.ErrWrongRequest, "Unsupported content-type: %s", contentType)
}
if errUnMarshall != nil {
return sdk.NewError(sdk.ErrWrongRequest, errUnMarshall)
return sdk.NewError(sdk.ErrWrongRequest, errUnMarshall)
}

tx, err := api.mustDB().Begin()
Expand All @@ -53,7 +53,7 @@ func (api *API) postWorkerModelImportHandler() service.Handler {
}
defer tx.Rollback() //nolint

wm, err := worker.ParseAndImport(tx, &eWorkerModel, force, getUser(ctx))
wm, err := worker.ParseAndImport(tx, api.Cache, &eWorkerModel, force, getUser(ctx))
if err != nil {
return sdk.WrapError(err, "cannot parse and import worker model")
}
Expand Down

0 comments on commit b88f80e

Please sign in to comment.