This is an automated email from the ASF dual-hosted git repository.

pabloem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e56b9a  [BEAM-13360][Playground] update validation step
     new 826e0fb  Merge pull request #16095 from [BEAM-13360][Playground] 
[Bugfix] Fix synchronous validators
4e56b9a is described below

commit 4e56b9a790f7b951ba9f45a7d6c274cd77d31bcb
Author: AydarZaynutdinov <[email protected]>
AuthorDate: Wed Dec 1 14:30:54 2021 +0300

    [BEAM-13360][Playground]
    update validation step
---
 playground/backend/internal/executors/executor.go | 26 +++++++++++++++++------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/playground/backend/internal/executors/executor.go 
b/playground/backend/internal/executors/executor.go
index b84d472..a29398b 100644
--- a/playground/backend/internal/executors/executor.go
+++ b/playground/backend/internal/executors/executor.go
@@ -20,6 +20,7 @@ import (
        "beam.apache.org/playground/backend/internal/validators"
        "context"
        "os/exec"
+       "sync"
 )
 
 //CmdConfiguration for base cmd code execution
@@ -41,15 +42,26 @@ type Executor struct {
 // Validate returns the function that applies all validators of executor
 func (ex *Executor) Validate() func(chan bool, chan error) {
        return func(doneCh chan bool, errCh chan error) {
+               validationErrors := make(chan error, len(ex.validators))
+               var wg sync.WaitGroup
                for _, validator := range ex.validators {
-                       err := validator.Validator(validator.Args...)
-                       if err != nil {
-                               errCh <- err
-                               doneCh <- false
-                               return
-                       }
+                       wg.Add(1)
+                       go func(validationErrors chan error, validator 
validators.Validator) {
+                               defer wg.Done()
+                               err := validator.Validator(validator.Args...)
+                               if err != nil {
+                                       validationErrors <- err
+                               }
+                       }(validationErrors, validator)
+               }
+               wg.Wait()
+               select {
+               case err := <-validationErrors:
+                       errCh <- err
+                       doneCh <- false
+               default:
+                       doneCh <- true
                }
-               doneCh <- true
        }
 }
 

Reply via email to