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,31 @@
|
||||
package render
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"evobgp/internal/store"
|
||||
)
|
||||
|
||||
// PublishLatestTenantRevision sets each speaker's published_revision_id to the newest tenant revision (by created_at).
|
||||
// Simplification for single-tenant / demo stacks; multi-module tenants may prefer explicit publish policies later.
|
||||
func PublishLatestTenantRevision(ctx context.Context, st store.Backend) {
|
||||
_ = ctx
|
||||
tenants, err := st.ListTenantIDs()
|
||||
if err != nil {
|
||||
log.Printf("evobgp-render: list tenants: %v", err)
|
||||
return
|
||||
}
|
||||
for _, tid := range tenants {
|
||||
revs, _, _ := st.ListRevisions(tid, "", "", 1)
|
||||
if len(revs) == 0 {
|
||||
continue
|
||||
}
|
||||
rid := revs[0].ID
|
||||
for _, sp := range st.ListSpeakersForTenant(tid) {
|
||||
if err := st.PublishRevisionForSpeaker(sp.ID, rid); err != nil {
|
||||
log.Printf("evobgp-render: publish speaker %s: %v", sp.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
-4
@@ -1,22 +1,55 @@
|
||||
// Package render materializes prefix sets, creates config_revision rows, and builds BIRD text via internal/birdfmt.
|
||||
package render
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"evobgp/internal/broker"
|
||||
"evobgp/internal/config"
|
||||
"evobgp/internal/store"
|
||||
)
|
||||
|
||||
// Run blocks until ctx is cancelled. Reference deployment: worker process after ingest completes.
|
||||
func Run(ctx context.Context) {
|
||||
// Deps enables auto-publish of the latest rendered revision to all speakers in each tenant.
|
||||
type Deps struct {
|
||||
Store store.Backend
|
||||
}
|
||||
|
||||
// Run blocks until ctx is cancelled. With Store set, periodically publishes the head revision for each tenant.
|
||||
func Run(ctx context.Context, deps *Deps) {
|
||||
cfg := config.Load()
|
||||
broker.LogConnect(ctx, cfg.BrokerURL)
|
||||
if deps == nil || deps.Store == nil {
|
||||
runStub(ctx)
|
||||
return
|
||||
}
|
||||
t := time.NewTicker(45 * time.Second)
|
||||
defer t.Stop()
|
||||
auto := strings.TrimSpace(os.Getenv("EVOBGP_RENDER_AUTOPUBLISH")) == "1"
|
||||
if auto {
|
||||
log.Printf("evobgp-render: active (EVOBGP_RENDER_AUTOPUBLISH=1: publish head revision per tenant)")
|
||||
} else {
|
||||
log.Printf("evobgp-render: active (idle publish; set EVOBGP_RENDER_AUTOPUBLISH=1 to auto-publish head revision)")
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Printf("evobgp-render: stopped")
|
||||
return
|
||||
case <-t.C:
|
||||
if auto {
|
||||
PublishLatestTenantRevision(context.Background(), deps.Store)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runStub(ctx context.Context) {
|
||||
t := time.NewTicker(60 * time.Second)
|
||||
defer t.Stop()
|
||||
log.Printf("evobgp-render: started (stub; render jobs produce revisions and artifacts)")
|
||||
log.Printf("evobgp-render: idle stub (no store in Deps)")
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
Reference in New Issue
Block a user