🐳 执行超时控制
This commit is contained in:
parent
a236fc195c
commit
e952c8fa09
|
@ -51,7 +51,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if conf.Docker {
|
if conf.Docker {
|
||||||
fileName := filepath.Base(filePath)
|
fileName := filepath.Base(filePath)
|
||||||
cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "--cpus", "0.1", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName)
|
cmd = exec.Command("timeout", "-s", "9", "5", "docker", "run", "--rm", "--cpus", "0.1", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName)
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command(filePath)
|
cmd = exec.Command(filePath)
|
||||||
curDir := filepath.Dir(filePath)
|
curDir := filepath.Dir(filePath)
|
||||||
|
@ -154,7 +154,9 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
Processes.Remove(wSession, cmd.Process)
|
Processes.Remove(wSession, cmd.Process)
|
||||||
|
|
||||||
channelRet["cmd"] = "run-done"
|
channelRet["cmd"] = "run-done"
|
||||||
if 124 == cmd.ProcessState.ExitCode() {
|
// timeout: https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html
|
||||||
|
exitCode := cmd.ProcessState.ExitCode()
|
||||||
|
if 124 == exitCode || 125 == exitCode || 137 == exitCode {
|
||||||
channelRet["output"] = "<span class='stderr'>run program timeout in 5s</span>\n"
|
channelRet["output"] = "<span class='stderr'>run program timeout in 5s</span>\n"
|
||||||
} else {
|
} else {
|
||||||
channelRet["output"] = "\n<span class='stderr'>run program complete</span>\n"
|
channelRet["output"] = "\n<span class='stderr'>run program complete</span>\n"
|
||||||
|
|
|
@ -52,7 +52,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if conf.Docker {
|
if conf.Docker {
|
||||||
fileName := filepath.Base(filePath)
|
fileName := filepath.Base(filePath)
|
||||||
cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "--cpus", "0.1", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName)
|
cmd = exec.Command("timeout", "-s", "9", "5", "docker", "run", "--rm", "--cpus", "0.1", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName)
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command(filePath)
|
cmd = exec.Command(filePath)
|
||||||
curDir := filepath.Dir(filePath)
|
curDir := filepath.Dir(filePath)
|
||||||
|
@ -156,7 +156,9 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
output.Processes.Remove(wSession, cmd.Process)
|
output.Processes.Remove(wSession, cmd.Process)
|
||||||
|
|
||||||
channelRet["cmd"] = "run-done"
|
channelRet["cmd"] = "run-done"
|
||||||
if 124 == cmd.ProcessState.ExitCode() {
|
// timeout: https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html
|
||||||
|
exitCode := cmd.ProcessState.ExitCode()
|
||||||
|
if 124 == exitCode || 125 == exitCode || 137 == exitCode {
|
||||||
channelRet["output"] = "\nrun program timeout in 5s\n"
|
channelRet["output"] = "\nrun program timeout in 5s\n"
|
||||||
}
|
}
|
||||||
if nil != wsChannel {
|
if nil != wsChannel {
|
||||||
|
|
Loading…
Reference in New Issue