refactor: update worker processes in EvoBGP to accept dependencies for shared store and job registry. Enhance scheduler, ingest, render, and deploy components to utilize a unified context and improve logging for drift detection. Update architecture documentation to reflect changes in process interactions and worker functionalities.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"evobgp/internal/db"
|
||||
"evobgp/internal/jobs"
|
||||
"evobgp/internal/observability"
|
||||
"evobgp/internal/repository"
|
||||
"evobgp/internal/store"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
// BootstrapWorkers opens the same store.Backend and jobs.Registry as New (without HTTP or bundle keys).
|
||||
// Used by standalone worker binaries (scheduler, ingest, …) that share PostgreSQL with the API.
|
||||
func BootstrapWorkers(ctx context.Context, opts Options) (store.Backend, *jobs.Registry, *pgxpool.Pool, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
|
||||
defer cancel()
|
||||
|
||||
var backend store.Backend
|
||||
var pool *pgxpool.Pool
|
||||
|
||||
if u := strings.TrimSpace(opts.DatabaseURL); u != "" {
|
||||
p, err := db.OpenPostgresPool(ctx, u)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
pool = p
|
||||
pgbe, err := repository.NewPostgres(ctx, p, opts.SeedDemo)
|
||||
if err != nil {
|
||||
pool.Close()
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
backend = pgbe
|
||||
} else {
|
||||
mem := store.NewMemory()
|
||||
if opts.SeedDemo {
|
||||
mem.SeedDemo()
|
||||
}
|
||||
backend = mem
|
||||
}
|
||||
|
||||
cdnHTTP := &http.Client{Timeout: 45 * time.Second}
|
||||
wk := &jobs.Worker{Store: backend, HTTPClient: cdnHTTP}
|
||||
reg := jobs.NewRegistry(wk.Process)
|
||||
observability.RegisterStoreBackend(backend)
|
||||
return backend, reg, pool, nil
|
||||
}
|
||||
Reference in New Issue
Block a user