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

@@ -0,0 +1,32 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.23.0
package repositories
import (
"context"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}

View File

@@ -0,0 +1,30 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.23.0
package repositories
import (
"github.com/google/uuid"
"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

@@ -0,0 +1,19 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.23.0
package repositories
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
type Querier interface {
GetLast(ctx context.Context, modelName string) (pgtype.Timestamptz, error)
Ping(ctx context.Context) (int32, error)
UpsertModel(ctx context.Context, arg *UpsertModelParams) error
}
var _ Querier = (*Queries)(nil)

View File

@@ -0,0 +1,57 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.23.0
// source: queries.sql
package repositories
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getLast = `-- name: GetLast :one
SELECT last_run
FROM
model_schedules
WHERE
model_name = $1
LIMIT 1
`
func (q *Queries) GetLast(ctx context.Context, modelName string) (pgtype.Timestamptz, error) {
row := q.db.QueryRow(ctx, getLast, modelName)
var last_run pgtype.Timestamptz
err := row.Scan(&last_run)
return last_run, err
}
const ping = `-- name: Ping :one
SELECT 1
`
func (q *Queries) Ping(ctx context.Context) (int32, error) {
row := q.db.QueryRow(ctx, ping)
var column_1 int32
err := row.Scan(&column_1)
return column_1, err
}
const upsertModel = `-- name: UpsertModel :exec
INSERT INTO model_schedules (model_name, last_run)
VALUES ($1, $2)
ON CONFLICT (model_name)
DO UPDATE SET
last_run = excluded.last_run
`
type UpsertModelParams struct {
ModelName string `json:"model_name"`
LastRun pgtype.Timestamptz `json:"last_run"`
}
func (q *Queries) UpsertModel(ctx context.Context, arg *UpsertModelParams) error {
_, err := q.db.Exec(ctx, upsertModel, arg.ModelName, arg.LastRun)
return err
}