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

Method invoke

runtime/controller.go:1281–1353  ·  view source on GitHub ↗

invoke starts a goroutine for reconciling the resource and tracks the invocation in c.invocations. It must be called while c.mu is held.

(r *runtimev1.Resource)

Source from the content-addressed store, hash-verified

1279// invoke starts a goroutine for reconciling the resource and tracks the invocation in c.invocations.
1280// It must be called while c.mu is held.
1281func (c *Controller) invoke(r *runtimev1.Resource) error {
1282 // Set status to running
1283 n := r.Meta.Name
1284 err := c.catalog.updateStatus(n, runtimev1.ReconcileStatus_RECONCILE_STATUS_RUNNING, time.Time{})
1285 if err != nil {
1286 return fmt.Errorf("error updating dag node %q: %w", nameStr(n), err)
1287 }
1288
1289 // Track invocation
1290 ctx, cancel := context.WithCancel(context.Background())
1291 inv := &invocation{
1292 name: n,
1293 isHidden: r.Meta.Hidden,
1294 isDelete: r.Meta.DeletedOn != nil,
1295 isRename: r.Meta.RenamedFrom != nil,
1296 startedOn: time.Now(),
1297 cancelFn: cancel,
1298 }
1299 c.invocations[nameStr(n)] = inv
1300
1301 // Log invocation
1302 logArgs := []zap.Field{zap.String("name", n.Name), zap.String("type", PrettifyResourceKind(n.Kind))}
1303 if inv.isDelete {
1304 logArgs = append(logArgs, zap.Bool("deleted", inv.isDelete))
1305 }
1306 if inv.isRename {
1307 logArgs = append(logArgs, zap.String("renamed_from", r.Meta.RenamedFrom.Name))
1308 }
1309 c.Logger.Info("Reconciling resource", logArgs...)
1310
1311 // Start reconcile in background
1312 ctx = contextWithInvocation(ctx, inv)
1313 go func() {
1314 defer func() {
1315 // Catch panics and set as error
1316 if r := recover(); r != nil {
1317 stack := make([]byte, 64<<10)
1318 stack = stack[:runtime.Stack(stack, false)]
1319 c.Logger.Error("panic in reconciler", zap.String("name", n.Name), zap.String("type", n.Kind), zap.Any("error", r), zap.String("stack", string(stack)))
1320
1321 inv.result = ReconcileResult{Err: fmt.Errorf("panic: %v", r)}
1322 if inv.holdsLock {
1323 c.Unlock(ctx)
1324 }
1325 }
1326 // Ensure ctx cancel is called (just for cleanup)
1327 cancel()
1328 // Send invocation to event loop for post-processing
1329 c.completed <- inv
1330 }()
1331
1332 // Start tracing span
1333 reconciler := c.reconciler(n.Kind)
1334 tracerAttrs := []attribute.KeyValue{
1335 attribute.String("instance_id", c.InstanceID),
1336 attribute.String("name", n.Name),
1337 attribute.String("type", PrettifyResourceKind(n.Kind)),
1338 }

Callers 1

tryScheduleMethod · 0.95

Calls 12

UnlockMethod · 0.95
reconcilerMethod · 0.95
nameStrFunction · 0.85
PrettifyResourceKindFunction · 0.85
contextWithInvocationFunction · 0.85
recoverFunction · 0.85
updateStatusMethod · 0.80
InfoMethod · 0.80
ErrorfMethod · 0.65
StringMethod · 0.65
ReconcileMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected