| 36 | |
| 37 | // POST /jobs |
| 38 | async run_job(req, res) { |
| 39 | const runtime = get_latest_runtime_matching_language_version(req.body.language, req.body.version); |
| 40 | |
| 41 | if (runtime === undefined) { |
| 42 | return res |
| 43 | .status(400) |
| 44 | .send({ |
| 45 | message: `${req.body.language}-${req.body.version} runtime is unknown` |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | const job = new Job({ |
| 50 | runtime, |
| 51 | alias: req.body.language, |
| 52 | files: req.body.files, |
| 53 | args: req.body.args, |
| 54 | stdin: req.body.stdin, |
| 55 | timeouts: { |
| 56 | run: req.body.run_timeout, |
| 57 | compile: req.body.compile_timeout |
| 58 | }, |
| 59 | main: req.body.main |
| 60 | }); |
| 61 | |
| 62 | await job.prime(); |
| 63 | |
| 64 | const result = await job.execute(); |
| 65 | |
| 66 | await job.cleanup(); |
| 67 | |
| 68 | return res |
| 69 | .status(200) |
| 70 | .send(result); |
| 71 | } |
| 72 | |
| 73 | }; |