worker: require workers to declare job types they accept
For now, workers must send `[ "osbuild" ]`.
This commit is contained in:
parent
d3c99b8e93
commit
ba6a480e32
5 changed files with 21 additions and 4 deletions
|
|
@ -16,7 +16,9 @@ type Error struct {
|
|||
}
|
||||
|
||||
// RequestJobJSONBody defines parameters for RequestJob.
|
||||
type RequestJobJSONBody map[string]interface{}
|
||||
type RequestJobJSONBody struct {
|
||||
Types []string `json:"types"`
|
||||
}
|
||||
|
||||
// UpdateJobJSONBody defines parameters for UpdateJob.
|
||||
type UpdateJobJSONBody struct {
|
||||
|
|
|
|||
|
|
@ -83,6 +83,15 @@ paths:
|
|||
schema:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
properties:
|
||||
types:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
enum:
|
||||
- osbuild
|
||||
required:
|
||||
- types
|
||||
description: ''
|
||||
description: Requests a job. This operation blocks until a job is available.
|
||||
parameters: []
|
||||
|
|
|
|||
|
|
@ -82,7 +82,9 @@ func (c *Client) RequestJob() (Job, error) {
|
|||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err = json.NewEncoder(&buf).Encode(api.RequestJobJSONRequestBody{})
|
||||
err = json.NewEncoder(&buf).Encode(api.RequestJobJSONRequestBody{
|
||||
Types: []string{"osbuild"},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,12 +252,16 @@ func (h *apiHandlers) GetStatus(ctx echo.Context) error {
|
|||
}
|
||||
|
||||
func (h *apiHandlers) RequestJob(ctx echo.Context) error {
|
||||
var body struct{}
|
||||
var body api.RequestJobJSONRequestBody
|
||||
err := ctx.Bind(&body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(body.Types) != 1 || body.Types[0] != "osbuild" {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "invalid job types")
|
||||
}
|
||||
|
||||
token, jobId, jobArgs, err := h.server.RequestJob(ctx.Request().Context())
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func TestCreate(t *testing.T) {
|
|||
_, err = server.Enqueue(manifest, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
test.TestRoute(t, server, false, "POST", "/jobs", `{}`, http.StatusCreated,
|
||||
test.TestRoute(t, server, false, "POST", "/jobs", `{"types":["osbuild"]}`, http.StatusCreated,
|
||||
`{"type":"osbuild","args":{"manifest":{"pipeline":{},"sources":{}}}}`, "id", "location", "artifact_location")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue