Skip to content

Instantly share code, notes, and snippets.

@dom96
Created April 23, 2017 13:18
Show Gist options
  • Save dom96/f00fed7f9a635178d4e7a062c960c171 to your computer and use it in GitHub Desktop.
Save dom96/f00fed7f9a635178d4e7a062c960c171 to your computer and use it in GitHub Desktop.
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