Manager: move FetchJob function into jobs_query.go

I want to put more of the "get stuff" code into `jobs_query.go`, keeping
`jobs.go` for creationg & manipulation.
This commit is contained in:
Sybren A. Stüvel 2022-04-22 11:51:02 +02:00
parent fc4cc11483
commit 0cd478a409
2 changed files with 25 additions and 23 deletions

View File

@ -97,29 +97,6 @@ func (f *Flamenco) SubmitJob(e echo.Context) error {
return e.JSON(http.StatusOK, apiJob)
}
func (f *Flamenco) FetchJob(e echo.Context, jobId string) error {
logger := requestLogger(e).With().
Str("job", jobId).
Logger()
if _, err := uuid.Parse(jobId); err != nil {
logger.Debug().Msg("invalid job ID received")
return sendAPIError(e, http.StatusBadRequest, "job ID not valid")
}
logger.Debug().Msg("fetching job")
ctx := e.Request().Context()
dbJob, err := f.persist.FetchJob(ctx, jobId)
if err != nil {
logger.Warn().Err(err).Msg("cannot fetch job")
return sendAPIError(e, http.StatusNotFound, fmt.Sprintf("job %+v not found", jobId))
}
apiJob := jobDBtoAPI(dbJob)
return e.JSON(http.StatusOK, apiJob)
}
func (f *Flamenco) SetJobStatus(e echo.Context, jobID string) error {
logger := requestLogger(e)
ctx := e.Request().Context()

View File

@ -2,12 +2,37 @@
package api_impl
import (
"fmt"
"net/http"
"git.blender.org/flamenco/pkg/api"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
)
func (f *Flamenco) FetchJob(e echo.Context, jobId string) error {
logger := requestLogger(e).With().
Str("job", jobId).
Logger()
if _, err := uuid.Parse(jobId); err != nil {
logger.Debug().Msg("invalid job ID received")
return sendAPIError(e, http.StatusBadRequest, "job ID not valid")
}
logger.Debug().Msg("fetching job")
ctx := e.Request().Context()
dbJob, err := f.persist.FetchJob(ctx, jobId)
if err != nil {
logger.Warn().Err(err).Msg("cannot fetch job")
return sendAPIError(e, http.StatusNotFound, fmt.Sprintf("job %+v not found", jobId))
}
apiJob := jobDBtoAPI(dbJob)
return e.JSON(http.StatusOK, apiJob)
}
func (f *Flamenco) QueryJobs(e echo.Context) error {
logger := requestLogger(e)