MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / NewManager

Function NewManager

internal/senderidentity/manager.go:56–95  ·  view source on GitHub ↗

NewManager builds the River client with the provision/reconcile/deprovision workers + the periodic orphan reaper. The DB must already have River's schema (call Migrate first). fire may be nil (no events).

(pool *pgxpool.Pool, store Store, provider Provider, fire EventFirer, cfg Config)

Source from the content-addressed store, hash-verified

54// workers + the periodic orphan reaper. The DB must already have River's
55// schema (call Migrate first). fire may be nil (no events).
56func NewManager(pool *pgxpool.Pool, store Store, provider Provider, fire EventFirer, cfg Config) (*Manager, error) {
57 maxWorkers := cfg.MaxWorkers
58 if maxWorkers <= 0 {
59 maxWorkers = 5
60 }
61 reaperInterval := cfg.ReaperInterval
62 if reaperInterval <= 0 {
63 reaperInterval = defaultReaperInterval
64 }
65
66 workers := river.NewWorkers()
67 river.AddWorker(workers, &ProvisionWorker{store: store, provider: provider, fire: fire, maxReconcileAttempt: cfg.MaxReconcileAttempts})
68 river.AddWorker(workers, &ReconcileWorker{store: store, provider: provider, fire: fire})
69 river.AddWorker(workers, &DeprovisionWorker{provider: provider})
70 river.AddWorker(workers, &ReapWorker{store: store, provider: provider})
71
72 periodic := []*river.PeriodicJob{
73 river.NewPeriodicJob(
74 river.PeriodicInterval(reaperInterval),
75 func() (river.JobArgs, *river.InsertOpts) {
76 // No UniqueOpts: River's periodic scheduler already inserts at
77 // most one per interval, and a completed reap must not dedup-
78 // block the next scheduled run (River can't drop `completed`
79 // from a unique state set). The reaper is idempotent anyway.
80 return ReapArgs{}, nil
81 },
82 &river.PeriodicJobOpts{RunOnStart: false},
83 ),
84 }
85
86 client, err := river.NewClient(riverpgxv5.New(pool), &river.Config{
87 Queues: map[string]river.QueueConfig{river.QueueDefault: {MaxWorkers: maxWorkers}},
88 Workers: workers,
89 PeriodicJobs: periodic,
90 })
91 if err != nil {
92 return nil, fmt.Errorf("river client: %w", err)
93 }
94 return &Manager{client: client}, nil
95}
96
97// Start begins working jobs. Non-blocking.
98func (m *Manager) Start(ctx context.Context) error { return m.client.Start(ctx) }

Callers 5

TestProvisionToVerifiedFunction · 0.92
TestProvisionFailsClosedFunction · 0.92
TestDeprovisionTeardownFunction · 0.92
mainFunction · 0.92

Calls

no outgoing calls

Tested by 4

TestProvisionToVerifiedFunction · 0.74
TestProvisionFailsClosedFunction · 0.74
TestDeprovisionTeardownFunction · 0.74