(req *proto.FunctionProcessRequest, stream proto.Function_ProcessServer)
| 248 | } |
| 249 | |
| 250 | func (f *FunctionServerImpl) Process(req *proto.FunctionProcessRequest, stream proto.Function_ProcessServer) error { |
| 251 | runtime, err := f.reconcileSvr.getFunc(req.Name) |
| 252 | if err != nil { |
| 253 | return err |
| 254 | } |
| 255 | log := runtime.log |
| 256 | log.Info("Start processing events using GRPC") |
| 257 | runtime.readyOnce.Do(func() { |
| 258 | runtime.readyCh <- err |
| 259 | }) |
| 260 | errCh := make(chan error) |
| 261 | |
| 262 | defer func() { |
| 263 | if runtime.processing.Load() { |
| 264 | runtime.output <- nil |
| 265 | runtime.processing.Store(false) |
| 266 | } |
| 267 | }() |
| 268 | |
| 269 | logCounter := common.LogCounter() |
| 270 | for { |
| 271 | select { |
| 272 | case event := <-runtime.input: |
| 273 | log.Debug("sending event", "count", logCounter) |
| 274 | runtime.processing.Store(true) |
| 275 | err := stream.Send(&proto.Event{Payload: string(event.GetPayload())}) // TODO: Change payload type to bytes |
| 276 | if err != nil { |
| 277 | log.Error(err, "failed to send event") |
| 278 | return err |
| 279 | } |
| 280 | case <-stream.Context().Done(): |
| 281 | return nil |
| 282 | case <-runtime.ctx.Done(): |
| 283 | return nil |
| 284 | case e := <-errCh: |
| 285 | return e |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | func (f *FunctionServerImpl) getFunctionRuntime(ctx context.Context) (*FuncRuntime, error) { |
| 291 | md, ok := metadata.FromIncomingContext(ctx) |
nothing calls this directly
no test coverage detected