Mercurial > gemma
changeset 1748:c11807dc6940
Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 10 Jan 2019 14:52:26 +0100 |
parents | 90178f4ce255 |
children | 0a6b2ace7b7e |
files | pkg/controllers/importconfig.go pkg/controllers/routes.go pkg/imports/scheduled.go |
diffstat | 3 files changed, 17 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/importconfig.go Thu Jan 10 14:33:10 2019 +0100 +++ b/pkg/controllers/importconfig.go Thu Jan 10 14:52:26 2019 +0100 @@ -86,13 +86,15 @@ func runImportConfig( _ interface{}, req *http.Request, - _ *sql.Conn, + conn *sql.Conn, ) (jr JSONResult, err error) { id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) + ctx := req.Context() + var jobID int64 - if jobID, err = imports.RunConfiguredImport(id); err != nil { + if jobID, err = imports.RunConfiguredImportContext(ctx, conn, id); err != nil { return }
--- a/pkg/controllers/routes.go Thu Jan 10 14:33:10 2019 +0100 +++ b/pkg/controllers/routes.go Thu Jan 10 14:52:26 2019 +0100 @@ -203,7 +203,6 @@ api.Handle("/imports/config/{id:[0-9]+}/run", waterwayAdmin(&JSONHandler{ Handle: runImportConfig, - NoConn: true, })).Methods(http.MethodGet) api.Handle("/imports/config/{id:[0-9]+}",
--- a/pkg/imports/scheduled.go Thu Jan 10 14:33:10 2019 +0100 +++ b/pkg/imports/scheduled.go Thu Jan 10 14:52:26 2019 +0100 @@ -14,6 +14,8 @@ package imports import ( + "context" + "database/sql" "errors" "fmt" "log" @@ -85,9 +87,20 @@ } } +// RunConfiguredImportContext runs an import configured from the database. +func RunConfiguredImportContext(ctx context.Context, conn *sql.Conn, id int64) (int64, error) { + cfg, err := LoadIDConfigContext(ctx, conn, id) + return runConfiguredImport(id, cfg, err) +} + // RunConfiguredImport runs an import configured from the database. func RunConfiguredImport(id int64) (int64, error) { cfg, err := loadIDConfig(id) + return runConfiguredImport(id, cfg, err) +} + +func runConfiguredImport(id int64, cfg *IDConfig, err error) (int64, error) { + if err != nil { return 0, err }