MCPcopy Index your code
hub / github.com/rilldata/rill / TriggerParserAndAwaitResource

Method TriggerParserAndAwaitResource

admin/projects.go:476–540  ·  view source on GitHub ↗

TriggerParserAndAwaitResource triggers the parser and polls the runtime until the given resource's spec version has been updated (or ctx is canceled).

(ctx context.Context, depl *database.Deployment, name, kind string)

Source from the content-addressed store, hash-verified

474
475// TriggerParserAndAwaitResource triggers the parser and polls the runtime until the given resource's spec version has been updated (or ctx is canceled).
476func (s *Service) TriggerParserAndAwaitResource(ctx context.Context, depl *database.Deployment, name, kind string) error {
477 rt, err := s.OpenRuntimeClient(depl)
478 if err != nil {
479 return err
480 }
481 defer rt.Close()
482
483 resourceReq := &runtimev1.GetResourceRequest{
484 InstanceId: depl.RuntimeInstanceID,
485 Name: &runtimev1.ResourceName{
486 Kind: kind,
487 Name: name,
488 },
489 }
490
491 // Get old spec version
492 var oldSpecVersion *int64
493 r, err := rt.GetResource(ctx, resourceReq)
494 if err == nil {
495 oldSpecVersion = &r.Resource.Meta.SpecVersion
496 }
497
498 // Trigger parser
499 _, err = rt.CreateTrigger(ctx, &runtimev1.CreateTriggerRequest{
500 InstanceId: depl.RuntimeInstanceID,
501 Parser: true,
502 })
503 if err != nil {
504 return err
505 }
506
507 // Poll every 1 seconds until the resource is found or the ctx is cancelled or times out
508 ctx, cancel := context.WithTimeout(ctx, time.Minute)
509 defer cancel()
510 ticker := time.NewTicker(time.Second)
511 defer ticker.Stop()
512 for {
513 select {
514 case <-ctx.Done():
515 return ctx.Err()
516 case <-ticker.C:
517 }
518
519 r, err := rt.GetResource(ctx, resourceReq)
520 if err != nil {
521 if s, ok := status.FromError(err); !ok || s.Code() != codes.NotFound {
522 return fmt.Errorf("failed to poll for resource: %w", err)
523 }
524 if oldSpecVersion != nil {
525 // Success - previously the resource was found, now we cannot find it anymore
526 return nil
527 }
528 // Continue polling
529 continue
530 }
531 if oldSpecVersion == nil {
532 // Success - previously the resource was not found, now we found one
533 return nil

Callers 8

CreateReportMethod · 0.80
EditReportMethod · 0.80
UnsubscribeReportMethod · 0.80
DeleteReportMethod · 0.80
CreateAlertMethod · 0.80
EditAlertMethod · 0.80
UnsubscribeAlertMethod · 0.80
DeleteAlertMethod · 0.80

Calls 7

OpenRuntimeClientMethod · 0.95
DoneMethod · 0.80
CloseMethod · 0.65
GetResourceMethod · 0.65
CreateTriggerMethod · 0.65
ErrMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected