feat: add worker distributor and model registry
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
32
internal/modelschedule/repositories/db.go
Normal file
32
internal/modelschedule/repositories/db.go
Normal 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,
|
||||
}
|
||||
}
|
30
internal/modelschedule/repositories/models.go
Normal file
30
internal/modelschedule/repositories/models.go
Normal 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"`
|
||||
}
|
19
internal/modelschedule/repositories/querier.go
Normal file
19
internal/modelschedule/repositories/querier.go
Normal 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)
|
57
internal/modelschedule/repositories/queries.sql.go
Normal file
57
internal/modelschedule/repositories/queries.sql.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user