AydarZaynutdinov commented on a change in pull request #16611:
URL: https://github.com/apache/beam/pull/16611#discussion_r798393532



##########
File path: playground/backend/internal/code_processing/code_processing.go
##########
@@ -406,6 +409,32 @@ func cancelCheck(ctx context.Context, pipelineId 
uuid.UUID, cancelChannel chan b
        }
 }
 
+// readGraphFile reads graph from the log file and keeps it to the cache.
+// If context is done it means that the code processing was finished 
(successfully/with error/timeout). Write no graph to the cache.
+// If <-startReadGraphChannel it means that the graph written to the file and 
can be read.
+// In other case each pauseDuration checks that graph file exists or not.
+func readGraphFile(pipelineLifeCycleCtx, backgroundCtx context.Context, 
cacheService cache.Cache, graphFilePath string, pipelineId uuid.UUID) {
+       startReadGraphChannel := make(chan bool, 1)
+       ticker := time.NewTicker(pauseDuration)
+       for {
+               select {
+               // in case of timeout or cancel
+               case <-pipelineLifeCycleCtx.Done():
+                       ticker.Stop()
+                       return
+               // in case of graph file exists and can be read
+               case <-startReadGraphChannel:
+                       utils.ReadAndSetToCacheGraph(backgroundCtx, 
cacheService, pipelineId, graphFilePath)
+                       return
+               // waiting when graph file appears
+               case <-ticker.C:

Review comment:
       We can combine the second and the third cases. 

##########
File path: playground/backend/internal/code_processing/code_processing.go
##########
@@ -406,6 +409,32 @@ func cancelCheck(ctx context.Context, pipelineId 
uuid.UUID, cancelChannel chan b
        }
 }
 
+// readGraphFile reads graph from the log file and keeps it to the cache.
+// If context is done it means that the code processing was finished 
(successfully/with error/timeout). Write no graph to the cache.
+// If <-startReadGraphChannel it means that the graph written to the file and 
can be read.
+// In other case each pauseDuration checks that graph file exists or not.
+func readGraphFile(pipelineLifeCycleCtx, backgroundCtx context.Context, 
cacheService cache.Cache, graphFilePath string, pipelineId uuid.UUID) {
+       startReadGraphChannel := make(chan bool, 1)
+       ticker := time.NewTicker(pauseDuration)
+       for {
+               select {
+               // in case of timeout or cancel
+               case <-pipelineLifeCycleCtx.Done():
+                       ticker.Stop()
+                       return
+               // in case of graph file exists and can be read
+               case <-startReadGraphChannel:

Review comment:
       It seems that would be better to add something like this:
   ```
   if _, err := os.Stat(graphFilePath); err == nil {
           utils.ReadAndSetToCacheGraph(backgroundCtx, cacheService, 
pipelineId, graphFilePath)
        return
   }
   ``` 
   into first case after `ticker.Stop()`




-- 
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]


Reply via email to