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

@@ -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
}