Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into chore/frontend-pin-sw…
Browse files Browse the repository at this point in the history
…agger
  • Loading branch information
steebchen committed Jul 1, 2024
2 parents bbaffb5 + cc23233 commit 8383a52
Show file tree
Hide file tree
Showing 53 changed files with 1,048 additions and 242 deletions.
4 changes: 4 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ tasks:
lint-frontend:
cmds:
- cd frontend/app/ && pnpm run lint:check
format-prisma:
cmds:
- go run github.com/steebchen/prisma-client-go format
kill-query-engines:
cmds:
- ps -A | grep 'prisma-query-engine-darwin-arm64' | grep -v grep | awk '{print $1}' | xargs kill -9 $1
Expand All @@ -175,4 +178,5 @@ tasks:
deps:
- pre-commit-install
cmds:
- task: format-prisma
- pre-commit run --all-files || pre-commit run --all-files
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
5 changes: 5 additions & 0 deletions api-contracts/openapi/components/schemas/api_tokens.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ CreateAPITokenRequest:
type: string
description: A name for the API token.
maxLength: 255
expiresIn:
type: string
description: The duration for which the token is valid.
x-oapi-codegen-extra-tags:
validate: "omitnil,duration"
required:
- name

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
19 changes: 18 additions & 1 deletion api/v1/server/handlers/api-tokens/create.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package apitokens

import (
"time"

"github.com/labstack/echo/v4"

"github.com/hatchet-dev/hatchet/api/v1/server/oas/apierrors"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/db"
)
Expand All @@ -17,7 +20,21 @@ func (a *APITokenService) ApiTokenCreate(ctx echo.Context, request gen.ApiTokenC
return gen.ApiTokenCreate400JSONResponse(*apiErrors), nil
}

token, err := a.config.Auth.JWTManager.GenerateTenantToken(ctx.Request().Context(), tenant.ID, request.Body.Name)
var expiresAt *time.Time

if request.Body.ExpiresIn != nil {
expiresIn, err := time.ParseDuration(*request.Body.ExpiresIn)

if err != nil {
return gen.ApiTokenCreate400JSONResponse(apierrors.NewAPIErrors("invalid expiration duration")), nil
}

e := time.Now().UTC().Add(expiresIn)

expiresAt = &e
}

token, err := a.config.Auth.JWTManager.GenerateTenantToken(ctx.Request().Context(), tenant.ID, request.Body.Name, expiresAt)

if err != nil {
return nil, err
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

0 comments on commit 8383a52

Please sign in to comment.