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:
+53
-5
@@ -1,4 +1,3 @@
|
||||
// Package deploy delivers generated BIRD fragments to evobgp-agent / publishes signed bundles for evobgp-node.
|
||||
package deploy
|
||||
|
||||
import (
|
||||
@@ -10,18 +9,67 @@ import (
|
||||
|
||||
"evobgp/internal/broker"
|
||||
"evobgp/internal/config"
|
||||
"evobgp/internal/store"
|
||||
)
|
||||
|
||||
// Run blocks until ctx is cancelled. Reference deployment: worker after render, talks to agent API or shared volume.
|
||||
func Run(ctx context.Context) {
|
||||
// Deps enables deploy-side drift logging between published and last-applied revision per speaker.
|
||||
type Deps struct {
|
||||
Store store.Backend
|
||||
}
|
||||
|
||||
// Run blocks until ctx is cancelled.
|
||||
func Run(ctx context.Context, deps *Deps) {
|
||||
cfg := config.Load()
|
||||
broker.LogConnect(ctx, cfg.BrokerURL)
|
||||
if d := strings.TrimSpace(os.Getenv("EVOBGP_BIRD_ACTIVE_DIR")); d != "" {
|
||||
log.Printf("evobgp-deploy: EVOBGP_BIRD_ACTIVE_DIR=%q (apply handled by API jobs + birddeploy when set on API)", d)
|
||||
log.Printf("evobgp-deploy: EVOBGP_BIRD_ACTIVE_DIR=%q (apply via API jobs when API has same env)", d)
|
||||
}
|
||||
if deps == nil || deps.Store == nil {
|
||||
runStub(ctx)
|
||||
return
|
||||
}
|
||||
t := time.NewTicker(90 * time.Second)
|
||||
defer t.Stop()
|
||||
log.Printf("evobgp-deploy: active (speaker published vs applied drift log)")
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Printf("evobgp-deploy: stopped")
|
||||
return
|
||||
case <-t.C:
|
||||
logDrift(context.Background(), deps.Store)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func logDrift(ctx context.Context, st store.Backend) {
|
||||
_ = ctx
|
||||
tenants, err := st.ListTenantIDs()
|
||||
if err != nil {
|
||||
log.Printf("evobgp-deploy: list tenants: %v", err)
|
||||
return
|
||||
}
|
||||
for _, tid := range tenants {
|
||||
for _, sp := range st.ListSpeakersForTenant(tid) {
|
||||
pub, _, err := st.LatestPublishedRevision(sp.ID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
applied := ""
|
||||
if sp.LastAppliedRevisionID != nil {
|
||||
applied = *sp.LastAppliedRevisionID
|
||||
}
|
||||
if applied != "" && applied != pub {
|
||||
log.Printf("evobgp-deploy: drift speaker=%s applied=%s published=%s", sp.ID, applied, pub)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runStub(ctx context.Context) {
|
||||
t := time.NewTicker(60 * time.Second)
|
||||
defer t.Stop()
|
||||
log.Printf("evobgp-deploy: started (orchestration stub; two-phase apply runs in evobgp-api/evobgp-all job worker when EVOBGP_BIRD_ACTIVE_DIR is set)")
|
||||
log.Printf("evobgp-deploy: idle stub (no store in Deps)")
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
Reference in New Issue
Block a user