Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: worker paused state #677

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api-contracts/openapi/components/schemas/_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ WorkerList:
$ref: "./worker.yaml#/WorkerList"
Worker:
$ref: "./worker.yaml#/Worker"
UpdateWorkerRequest:
$ref: "./worker.yaml#/UpdateWorkerRequest"
APIToken:
$ref: "./api_tokens.yaml#/APIToken"
CreateAPITokenRequest:
Expand Down
8 changes: 8 additions & 0 deletions api-contracts/openapi/components/schemas/worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Worker:
enum:
- ACTIVE
- INACTIVE
- PAUSED
maxRuns:
type: integer
description: The maximum number of runs this worker can execute concurrently.
Expand All @@ -49,6 +50,13 @@ Worker:
- name
type: object

UpdateWorkerRequest:
properties:
isPaused:
type: boolean
description: Whether the worker is paused and cannot accept new runs.
type: object

WorkerList:
properties:
pagination:
Expand Down
43 changes: 43 additions & 0 deletions api-contracts/openapi/paths/worker/worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,49 @@ withTenant:
- Worker

withWorker:
patch:
x-resources: ["tenant", "worker"]
description: Update a worker
operationId: worker:update
parameters:
- description: The worker id
in: path
name: worker
required: true
schema:
type: string
format: uuid
minLength: 36
maxLength: 36
requestBody:
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/UpdateWorkerRequest"
description: The worker update
required: true
responses:
"200":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/Worker"
description: Successfully updated the worker
"400":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/APIErrors"
description: A malformed or bad request
"403":
content:
application/json:
schema:
$ref: "../../components/schemas/_index.yaml#/APIErrors"
description: Forbidden
summary: Update worker
tags:
- Worker
get:
x-resources: ["tenant", "worker"]
description: Get a worker
Expand Down
2 changes: 1 addition & 1 deletion api/v1/server/handlers/workers/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (t *WorkerService) WorkerList(ctx echo.Context, request gen.WorkerListReque
workerCp := worker
slots := int(worker.Slots)

rows[i] = *transformers.ToWorkerSqlc(&workerCp.Worker, &worker.RunningStepRuns, &slots)
rows[i] = *transformers.ToWorkerSqlc(&workerCp.Worker, &slots)
}

return gen.WorkerList200JSONResponse(
Expand Down
35 changes: 35 additions & 0 deletions api/v1/server/handlers/workers/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package workers

import (
"github.com/labstack/echo/v4"

"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers"
"github.com/hatchet-dev/hatchet/pkg/repository"
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/db"
)

func (t *WorkerService) WorkerUpdate(ctx echo.Context, request gen.WorkerUpdateRequestObject) (gen.WorkerUpdateResponseObject, error) {
worker := ctx.Get("worker").(*db.WorkerModel)

// validate the request
if apiErrors, err := t.config.Validator.ValidateAPI(request.Body); err != nil {
return nil, err
} else if apiErrors != nil {
return gen.WorkerUpdate400JSONResponse(*apiErrors), nil
}

update := repository.ApiUpdateWorkerOpts{}

if request.Body.IsPaused != nil {
update.IsPaused = request.Body.IsPaused
}

updatedWorker, err := t.config.APIRepository.Worker().UpdateWorker(worker.TenantID, worker.ID, update)

if err != nil {
return nil, err
}

return gen.WorkerUpdate200JSONResponse(*transformers.ToWorkerSqlc(updatedWorker, nil)), nil
}
Loading
Loading