pabloem commented on a change in pull request #15996:
URL: https://github.com/apache/beam/pull/15996#discussion_r754769661
##########
File path: playground/backend/internal/code_processing/code_processing.go
##########
@@ -93,14 +105,27 @@ func Process(ctx context.Context, cacheService
cache.Cache, lc *fs_tool.LifeCycl
}
// build executor for run step
- exec = runBuilder.Build()
+ executor = runBuilder.Build()
// run
logger.Infof("%s: Run() ...\n", pipelineId)
- runCmd := exec.Run(ctxWithTimeout)
- go processCmd(runCmd, successChannel, errorChannel, dataChannel)
+ runCmd := executor.Run(ctxWithTimeout)
+
+ var runError bytes.Buffer
+ runOutput := &streaming.RunOutputWriter{Ctx: ctxWithTimeout,
CacheService: cacheService, PipelineId: pipelineId}
Review comment:
I am a little confused. I think `RunOutputWriter` fails if there has not
been any output, right? what happens at the very begining when there's no
output at all? what adds the very first output?
##########
File path: playground/backend/internal/streaming/run_output_writer.go
##########
@@ -0,0 +1,60 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package streaming
+
+import (
+ "beam.apache.org/playground/backend/internal/cache"
+ "context"
+ "fmt"
+ "github.com/google/uuid"
+)
+
+// RunOutputWriter is used to write the run step's output to cache as a stream.
+type RunOutputWriter struct {
+ Ctx context.Context
+ CacheService cache.Cache
+ PipelineId uuid.UUID
+}
+
+// Write writes len(p) bytes from p to cache with cache.RunOutput subKey.
+// In case some error occurs - returns (0, error).
+// In case finished with no error - returns (len(p), nil).
+//
+// As a result new bytes will be added to cache with old run output value.
+// Example:
+// p = []byte(" with new run output")
+// before Write(p): {pipelineId}:cache.RunOutput = "old run output"
+// after Write(p): {pipelineId}:cache.RunOutput = "old run output with new
run output"
+func (row *RunOutputWriter) Write(p []byte) (int, error) {
+ if len(p) == 0 {
+ return 0, nil
+ }
+
+ prevOutput, err := row.CacheService.GetValue(row.Ctx, row.PipelineId,
cache.RunOutput)
+ if err != nil {
+ return 0, err
+ }
+
+ // concat prevValue and new value
+ str := fmt.Sprintf("%s%s", prevOutput.(string), string(p))
Review comment:
it seems like redis supports an "append" operation that would save us
having to get the last value (https://redis.io/commands/append). Maybe we
should add this capability? (it's fine to leave for later)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]