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

Method WatchFiles

runtime/server/repos.go:56–101  ·  view source on GitHub ↗

WatchFiles implements RuntimeService.

(req *runtimev1.WatchFilesRequest, ss runtimev1.RuntimeService_WatchFilesServer)

Source from the content-addressed store, hash-verified

54
55// WatchFiles implements RuntimeService.
56func (s *Server) WatchFiles(req *runtimev1.WatchFilesRequest, ss runtimev1.RuntimeService_WatchFilesServer) error {
57 observability.AddRequestAttributes(ss.Context(),
58 attribute.String("args.instance_id", req.InstanceId),
59 attribute.Bool("args.replay", req.Replay),
60 )
61
62 if !auth.GetClaims(ss.Context(), req.InstanceId).Can(runtime.ReadRepo) {
63 return ErrForbidden
64 }
65
66 repo, release, err := s.runtime.Repo(ss.Context(), req.InstanceId)
67 if err != nil {
68 return err
69 }
70 defer release()
71
72 if req.Replay {
73 files, err := repo.ListGlob(ss.Context(), "**", false)
74 if err != nil {
75 return err
76 }
77 for _, f := range files {
78 err = ss.Send(&runtimev1.WatchFilesResponse{
79 Event: runtimev1.FileEvent_FILE_EVENT_WRITE,
80 Path: f.Path,
81 IsDir: f.IsDir,
82 })
83 if err != nil {
84 return err
85 }
86 }
87 }
88
89 return repo.Watch(ss.Context(), func(events []drivers.WatchEvent) {
90 for _, event := range events {
91 err := ss.Send(&runtimev1.WatchFilesResponse{
92 Event: event.Type,
93 Path: event.Path,
94 IsDir: event.Dir,
95 })
96 if err != nil {
97 s.logger.Info("failed to send watch event", zap.Error(err))
98 }
99 }
100 })
101}
102
103// GetFile implements RuntimeService.
104func (s *Server) GetFile(ctx context.Context, req *runtimev1.GetFileRequest) (*runtimev1.GetFileResponse, error) {

Callers 1

SSEHandlerMethod · 0.95

Calls 11

AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
CanMethod · 0.80
RepoMethod · 0.80
InfoMethod · 0.80
ContextMethod · 0.65
StringMethod · 0.65
ListGlobMethod · 0.65
SendMethod · 0.65
WatchMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected