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:
+25
-1
@@ -2,12 +2,15 @@ package jobs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"evobgp/internal/birddeploy"
|
||||
"evobgp/internal/birdfmt"
|
||||
"evobgp/internal/observability"
|
||||
"evobgp/internal/pipeline"
|
||||
"evobgp/internal/store"
|
||||
)
|
||||
|
||||
@@ -20,7 +23,17 @@ const (
|
||||
|
||||
// Worker executes queued jobs against store.Backend (memory or SQL).
|
||||
type Worker struct {
|
||||
Store store.Backend
|
||||
Store store.Backend
|
||||
HTTPClient *http.Client // optional; CDN refresh uses this (default 45s timeout).
|
||||
}
|
||||
|
||||
var defaultWorkerHTTP = &http.Client{Timeout: 45 * time.Second}
|
||||
|
||||
func (w *Worker) httpClient() *http.Client {
|
||||
if w != nil && w.HTTPClient != nil {
|
||||
return w.HTTPClient
|
||||
}
|
||||
return defaultWorkerHTTP
|
||||
}
|
||||
|
||||
// Process is registered as Registry.workerStart.
|
||||
@@ -42,6 +55,17 @@ func (w *Worker) Process(j *Job) {
|
||||
|
||||
switch j.Kind {
|
||||
case KindModuleRefresh:
|
||||
mid, _ := j.Meta["module_id"].(string)
|
||||
if strings.TrimSpace(mid) == "" {
|
||||
j.Fail("missing module_id in job meta")
|
||||
return
|
||||
}
|
||||
rev, err := pipeline.RefreshModule(context.Background(), w.Store, w.httpClient(), j.TenantID, mid)
|
||||
if err != nil {
|
||||
j.Fail(err.Error())
|
||||
return
|
||||
}
|
||||
j.mergeMeta(map[string]any{"revision_id": rev})
|
||||
j.Succeed()
|
||||
case KindDeployApply:
|
||||
w.runDeployApply(j)
|
||||
|
||||
Reference in New Issue
Block a user