Compare commits
1 Commits
072e908cf3
...
1819b214a6
Author | SHA1 | Date | |
---|---|---|---|
|
1819b214a6 |
@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## [0.1.0] - 2025-01-18
|
## [0.1.0] - 2025-01-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- prune old workers
|
|
||||||
- deregister worker on close
|
- deregister worker on close
|
||||||
- add worker distributor and model registry
|
- add worker distributor and model registry
|
||||||
- enable worker process
|
- enable worker process
|
||||||
|
@ -26,7 +26,7 @@ func (a *App) Logger() *slog.Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Scheduler() *scheduler.Scheduler {
|
func (a *App) Scheduler() *scheduler.Scheduler {
|
||||||
return scheduler.NewScheduler(a.logger.With("component", "scheduler"), Postgres(), a.Executor(), a.Worker())
|
return scheduler.NewScheduler(a.logger.With("component", "scheduler"), Postgres(), a.Executor())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Executor() *executor.Executor {
|
func (a *App) Executor() *executor.Executor {
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.front.kjuulh.io/kjuulh/orbis/internal/executor"
|
"git.front.kjuulh.io/kjuulh/orbis/internal/executor"
|
||||||
"git.front.kjuulh.io/kjuulh/orbis/internal/worker"
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
)
|
)
|
||||||
@ -18,15 +17,13 @@ type Scheduler struct {
|
|||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
db *pgxpool.Pool
|
db *pgxpool.Pool
|
||||||
executor *executor.Executor
|
executor *executor.Executor
|
||||||
worker *worker.Worker
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewScheduler(logger *slog.Logger, db *pgxpool.Pool, executor *executor.Executor, worker *worker.Worker) *Scheduler {
|
func NewScheduler(logger *slog.Logger, db *pgxpool.Pool, executor *executor.Executor) *Scheduler {
|
||||||
return &Scheduler{
|
return &Scheduler{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
db: db,
|
db: db,
|
||||||
executor: executor,
|
executor: executor,
|
||||||
worker: worker,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,10 +96,6 @@ func (s *Scheduler) acquireLeader(ctx context.Context) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scheduler) process(ctx context.Context) error {
|
func (s *Scheduler) process(ctx context.Context) error {
|
||||||
if err := s.worker.Prune(ctx); err != nil {
|
|
||||||
return fmt.Errorf("failed to prune error: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.executor.DispatchEvents(ctx); err != nil {
|
if err := s.executor.DispatchEvents(ctx); err != nil {
|
||||||
return fmt.Errorf("failed to dispatch events: %w", err)
|
return fmt.Errorf("failed to dispatch events: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,3 @@ WHERE
|
|||||||
DELETE FROM worker_register
|
DELETE FROM worker_register
|
||||||
WHERE
|
WHERE
|
||||||
worker_id = $1;
|
worker_id = $1;
|
||||||
|
|
||||||
-- name: PruneWorker :exec
|
|
||||||
DELETE FROM worker_register
|
|
||||||
WHERE
|
|
||||||
heart_beat <= now() - INTERVAL '10 minutes';
|
|
||||||
|
@ -14,7 +14,6 @@ type Querier interface {
|
|||||||
DeregisterWorker(ctx context.Context, workerID uuid.UUID) error
|
DeregisterWorker(ctx context.Context, workerID uuid.UUID) error
|
||||||
GetWorkers(ctx context.Context) ([]*GetWorkersRow, error)
|
GetWorkers(ctx context.Context) ([]*GetWorkersRow, error)
|
||||||
Ping(ctx context.Context) (int32, error)
|
Ping(ctx context.Context) (int32, error)
|
||||||
PruneWorker(ctx context.Context) error
|
|
||||||
RegisterWorker(ctx context.Context, arg *RegisterWorkerParams) error
|
RegisterWorker(ctx context.Context, arg *RegisterWorkerParams) error
|
||||||
UpdateWorkerHeartbeat(ctx context.Context, workerID uuid.UUID) error
|
UpdateWorkerHeartbeat(ctx context.Context, workerID uuid.UUID) error
|
||||||
}
|
}
|
||||||
|
@ -66,17 +66,6 @@ func (q *Queries) Ping(ctx context.Context) (int32, error) {
|
|||||||
return column_1, err
|
return column_1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const pruneWorker = `-- name: PruneWorker :exec
|
|
||||||
DELETE FROM worker_register
|
|
||||||
WHERE
|
|
||||||
heart_beat <= now() - INTERVAL '10 minutes'
|
|
||||||
`
|
|
||||||
|
|
||||||
func (q *Queries) PruneWorker(ctx context.Context) error {
|
|
||||||
_, err := q.db.Exec(ctx, pruneWorker)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
const registerWorker = `-- name: RegisterWorker :exec
|
const registerWorker = `-- name: RegisterWorker :exec
|
||||||
INSERT INTO worker_register (worker_id, capacity)
|
INSERT INTO worker_register (worker_id, capacity)
|
||||||
VALUES (
|
VALUES (
|
||||||
|
@ -173,9 +173,3 @@ func (w *Worker) updateHeartBeat(ctx context.Context) error {
|
|||||||
func (w *Worker) processWorkQueue(ctx context.Context) error {
|
func (w *Worker) processWorkQueue(ctx context.Context) error {
|
||||||
return w.workProcessor.ProcessNext(ctx, w.workerID)
|
return w.workProcessor.ProcessNext(ctx, w.workerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Worker) Prune(ctx context.Context) error {
|
|
||||||
repo := repositories.New(w.db)
|
|
||||||
|
|
||||||
return repo.PruneWorker(ctx)
|
|
||||||
}
|
|
||||||
|
@ -40,7 +40,7 @@ func (w *WorkProcessor) ProcessNext(ctx context.Context, workerID uuid.UUID) err
|
|||||||
return fmt.Errorf("failed to start processing items: %w", err)
|
return fmt.Errorf("failed to start processing items: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 10)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
if err := w.workscheduler.Archive(ctx, *schedule); err != nil {
|
if err := w.workscheduler.Archive(ctx, *schedule); err != nil {
|
||||||
return fmt.Errorf("failed to archive item: %w", err)
|
return fmt.Errorf("failed to archive item: %w", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user