Explorar o código

support max workers

Yeuoly hai 1 ano
pai
achega
f18842159e

+ 8 - 1
internal/controller/run.go

@@ -8,10 +8,17 @@ import (
 )
 
 var (
-	queue chan bool = make(chan bool, static.GetCoshubGlobalConfigurations().MaxWorkers)
+	queue chan bool
 )
 
+func InitSandBoxQueue() {
+	if queue == nil {
+		queue = make(chan bool, static.GetCoshubGlobalConfigurations().MaxWorkers)
+	}
+}
+
 func RunSandboxController(c *gin.Context) {
+
 	BindRequest(c, func(req struct {
 		Language string `json:"language" form:"language" binding:"required"`
 		Code     string `json:"code" form:"code" binding:"required"`

+ 0 - 1
internal/core/runner/python/python.go

@@ -137,7 +137,6 @@ func (p *PythonRunner) Run(code string, timeout time.Duration, stdin []byte) (ch
 			go func() {
 				var status syscall.WaitStatus
 				_, err := syscall.Wait4(int(pid), &status, 0, nil)
-				time.Sleep(time.Second)
 				if err != nil {
 					done <- err
 					return

+ 1 - 0
internal/server/server.go

@@ -26,6 +26,7 @@ func initServer() {
 
 	r := gin.Default()
 	controller.Setup(r)
+	controller.InitSandBoxQueue()
 
 	r.Run(fmt.Sprintf(":%d", config.App.Port))
 }