KhaninArtur commented on a change in pull request #16277:
URL: https://github.com/apache/beam/pull/16277#discussion_r773967325
##########
File path: playground/backend/internal/utils/system_utils.go
##########
@@ -16,14 +16,59 @@
package utils
import (
+ "beam.apache.org/playground/backend/internal/environment"
+ "beam.apache.org/playground/backend/internal/logger"
+ "net/http"
+ "os"
+ "path/filepath"
"reflect"
"runtime"
"strings"
)
+const (
+ executableFiles = "executable_files"
+)
+
// GetFuncName returns the name of the received func
func GetFuncName(i interface{}) string {
fullName := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
splitName := strings.Split(fullName, ".")
return splitName[len(splitName)-1]
}
+
+// GetReadinessFunction returns the function that checks the readiness of the
server to process a new code processing request
+func GetReadinessFunction(envs *environment.Environment) func(writer
http.ResponseWriter, request *http.Request) {
+ return func(writer http.ResponseWriter, request *http.Request) {
+ if checkNumOfTheParallelJobs(envs.ApplicationEnvs.WorkingDir(),
envs.BeamSdkEnvs.NumOfParallelJobs()) {
+ writer.WriteHeader(http.StatusOK)
+ } else {
+ writer.WriteHeader(http.StatusLocked)
+ }
+ }
+}
+
+// checkNumOfTheParallelJobs checks the number of already working code
processing.
+// It counts by the number of the
/path/to/workingDir/executable_files/{pipelineId} folders.
+// If it is equals or more than numOfParallelJobs, then returns false.
+// If it is less than numOfParallelJobs, then returns true.
+func checkNumOfTheParallelJobs(workingDir string, numOfParallelJobs int) bool {
+ // TODO add getting of dir executable_files from environments.
Review comment:
Do we have an issue ticket for this? Please, mention it here
##########
File path: playground/backend/internal/utils/system_utils_test.go
##########
@@ -42,3 +45,86 @@ func TestGetFuncName(t *testing.T) {
})
}
}
+
+func Test_checkNumOfTheParallelJobs(t *testing.T) {
+ baseFileFolder := "executable_files"
+ type args struct {
+ workingDir string
+ numOfParallelJobs int
+ }
+ tests := []struct {
+ name string
+ args args
+ prepareFunc func()
+ want bool
+ }{
+ {
+ // Test case with calling checkNumOfTheParallelJobs
when there is no code processing folders.
+ // As a result, want to receive true
+ name: "there is no code processing folders",
+ args: args{
+ workingDir: "",
+ numOfParallelJobs: 0,
+ },
+ prepareFunc: func() {},
+ want: true,
+ },
+ {
+ // Test case with calling checkNumOfTheParallelJobs
when there is one code processing folder.
+ // As a result, want to receive true
+ name: "there is one code processing folder",
+ args: args{
+ workingDir: "",
+ numOfParallelJobs: 2,
+ },
+ prepareFunc: func() {
+ err :=
os.MkdirAll(filepath.Join(baseFileFolder, "1"), fs.ModePerm)
+ if err != nil {
+ panic(err)
+ }
+ },
+ want: true,
+ },
+ {
+ // Test case with calling checkNumOfTheParallelJobs
when the number of the code processing folders is equals numOfParallelJobs.
+ // As a result, want to receive false
+ name: "there is one code processing folder",
+ args: args{
+ workingDir: "",
+ numOfParallelJobs: 1,
+ },
+ prepareFunc: func() {
+ err :=
os.MkdirAll(filepath.Join(baseFileFolder, "1"), fs.ModePerm)
+ if err != nil {
+ panic(err)
+ }
+ },
+ want: false,
+ },
+ {
+ // Test case with calling checkNumOfTheParallelJobs
when the number of the code processing folders is more than numOfParallelJobs.
+ // As a result, want to receive false
+ name: "there is one code processing folder",
Review comment:
I see you have same names for 3 tests above, let's make them different
--
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]