feat: add worker distributor and model registry
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-01-18 01:46:37 +01:00
parent 54aa310583
commit 2cdab4a1ab
28 changed files with 1169 additions and 29 deletions

View File

@@ -9,7 +9,22 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
type ModelSchedule struct {
ModelName string `json:"model_name"`
LastRun pgtype.Timestamptz `json:"last_run"`
}
type WorkSchedule struct {
ScheduleID uuid.UUID `json:"schedule_id"`
WorkerID uuid.UUID `json:"worker_id"`
StartRun pgtype.Timestamptz `json:"start_run"`
EndRun pgtype.Timestamptz `json:"end_run"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
State string `json:"state"`
}
type WorkerRegister struct {
WorkerID uuid.UUID `json:"worker_id"`
Capacity int32 `json:"capacity"`
HeartBeat pgtype.Timestamptz `json:"heart_beat"`
}

View File

@@ -11,8 +11,9 @@ import (
)
type Querier interface {
GetWorkers(ctx context.Context) ([]*GetWorkersRow, error)
Ping(ctx context.Context) (int32, error)
RegisterWorker(ctx context.Context, workerID uuid.UUID) error
RegisterWorker(ctx context.Context, arg *RegisterWorkerParams) error
UpdateWorkerHeartbeat(ctx context.Context, workerID uuid.UUID) error
}

View File

@@ -11,6 +11,39 @@ import (
"github.com/google/uuid"
)
const getWorkers = `-- name: GetWorkers :many
SELECT
worker_id
, capacity
FROM
worker_register
`
type GetWorkersRow struct {
WorkerID uuid.UUID `json:"worker_id"`
Capacity int32 `json:"capacity"`
}
func (q *Queries) GetWorkers(ctx context.Context) ([]*GetWorkersRow, error) {
rows, err := q.db.Query(ctx, getWorkers)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*GetWorkersRow{}
for rows.Next() {
var i GetWorkersRow
if err := rows.Scan(&i.WorkerID, &i.Capacity); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const ping = `-- name: Ping :one
SELECT 1
`
@@ -23,14 +56,20 @@ func (q *Queries) Ping(ctx context.Context) (int32, error) {
}
const registerWorker = `-- name: RegisterWorker :exec
INSERT INTO worker_register (worker_id)
INSERT INTO worker_register (worker_id, capacity)
VALUES (
$1
$1
, $2
)
`
func (q *Queries) RegisterWorker(ctx context.Context, workerID uuid.UUID) error {
_, err := q.db.Exec(ctx, registerWorker, workerID)
type RegisterWorkerParams struct {
WorkerID uuid.UUID `json:"worker_id"`
Capacity int32 `json:"capacity"`
}
func (q *Queries) RegisterWorker(ctx context.Context, arg *RegisterWorkerParams) error {
_, err := q.db.Exec(ctx, registerWorker, arg.WorkerID, arg.Capacity)
return err
}