MCPcopy Create free account
hub / github.com/rilldata/rill / NewController

Function NewController

runtime/controller.go:134–167  ·  view source on GitHub ↗

NewController creates a new Controller

(ctx context.Context, rt *Runtime, instanceID string, logger *zap.Logger, ac *activity.Client)

Source from the content-addressed store, hash-verified

132
133// NewController creates a new Controller
134func NewController(ctx context.Context, rt *Runtime, instanceID string, logger *zap.Logger, ac *activity.Client) (*Controller, error) {
135 c := &Controller{
136 Runtime: rt,
137 InstanceID: instanceID,
138 Logger: logger,
139 Activity: ac,
140 closedCh: make(chan struct{}),
141 reconcilers: make(map[string]Reconciler),
142 subscribers: make(map[int]SubscribeCallback),
143 idleWaits: make(map[int]idleWait),
144 queue: make(map[string]*runtimev1.ResourceName),
145 queueUpdatedCh: make(chan struct{}, 1),
146 timeline: schedule.New[string, *runtimev1.ResourceName](nameStr),
147 invocations: make(map[string]*invocation),
148 completed: make(chan *invocation),
149 }
150
151 cc, err := newCatalogCache(ctx, c, c.InstanceID)
152 if err != nil {
153 return nil, fmt.Errorf("failed to create catalog cache: %w", err)
154 }
155 c.catalog = cc
156
157 // Initialize all reconcilers
158 for kind, initializer := range ReconcilerInitializers {
159 reconciler, err := initializer(ctx, c)
160 if err != nil {
161 return nil, fmt.Errorf("failed to initialize reconciler for %q: %w", kind, err)
162 }
163 c.reconcilers[kind] = reconciler
164 }
165
166 return c, nil
167}
168
169// Run starts and runs the controller's event loop.
170// It returns when ctx is cancelled or an unrecoverable error occurs. Before returning, it closes the controller, so it must only be called once.

Callers 1

restartControllerMethod · 0.85

Calls 2

newCatalogCacheFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected