-
-
Save dom96/f00fed7f9a635178d4e7a062c960c171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jester, asyncdispatch, os, osproc, strutils, threadpool | |
proc respondOnReady(fv: FlowVar[TaintedString], resp: Response) {.async.} = | |
while true: | |
if fv.isReady: | |
assert ^fv == "" | |
resp.send(Http200, nil, readFile("tmp/logfile.txt")) | |
removeDir("./tmp") | |
await sleepAsync(500) | |
proc compile(resp: Response, code: string) = | |
let currentDir = getCurrentDir() | |
createDir("./tmp") | |
copyFileWithPermissions("./test/script.sh", "./tmp/script.sh") | |
writeFile("./tmp/in.nim", code) | |
let fv = spawn execProcess(""" | |
./docker_timeout.sh 20s -i -t -v "$1/tmp":/usercode virtual_machine /usercode/script.sh in.nim | |
""" % currentDir) | |
asyncCheck respondOnReady(fv, resp) | |
routes: | |
post "/compile": | |
if not request.formData.hasKey("code"): | |
resp Http400, "code missing from requests' form data." | |
response.data.action = TCActionRaw | |
compile(request.formData["code"].body) | |
runForever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment