Mercurial > gemma
changeset 1730:7c54babe10f7
Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 09 Jan 2019 13:11:09 +0100 |
parents | 74f7d4c531bc |
children | 8dd7452929ca |
files | pkg/controllers/importconfig.go pkg/controllers/routes.go |
diffstat | 2 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/importconfig.go Wed Jan 09 13:03:24 2019 +0100 +++ b/pkg/controllers/importconfig.go Wed Jan 09 13:11:09 2019 +0100 @@ -83,6 +83,32 @@ ` ) +func runImportConfig( + _ interface{}, + req *http.Request, + _ *sql.Conn, +) (jr JSONResult, err error) { + + id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) + + var jobID int64 + if jobID, err = imports.RunConfiguredImport(id); err != nil { + return + } + + var result = struct { + ID int64 `json:"id"` + }{ + ID: jobID, + } + + jr = JSONResult{ + Code: http.StatusCreated, + Result: &result, + } + return +} + func modifyImportConfig( input interface{}, req *http.Request,
--- a/pkg/controllers/routes.go Wed Jan 09 13:03:24 2019 +0100 +++ b/pkg/controllers/routes.go Wed Jan 09 13:11:09 2019 +0100 @@ -197,6 +197,12 @@ })).Methods(http.MethodPost) // Import scheduler configuration + api.Handle("/imports/config/{id:[0-9]+}/run", + waterwayAdmin(&JSONHandler{ + Handle: runImportConfig, + NoConn: true, + })).Methods(http.MethodGet) + api.Handle("/imports/config/{id:[0-9]+}", waterwayAdmin(&JSONHandler{ Handle: modifyImportConfig,