aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-02-08 17:15:18 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-02-08 17:15:18 +0200
commit12f1e04c9375bb399285d91bf16a44cc11080551 (patch)
tree6316f2366942d3e32ff1fe8e6225f19bc26f8bfa
parent29a4d3de2826e14241266e350ff2948537b5d1d5 (diff)
Add executionTime, apiTime to response
-rw-r--r--package-lock.json8
-rw-r--r--package.json2
-rw-r--r--src/index.ts14
3 files changed, 16 insertions, 8 deletions
diff --git a/package-lock.json b/package-lock.json
index c555644..02e49bd 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,7 +13,7 @@
"@tinyhttp/cors": "2.0.0",
"@tinyhttp/logger": "1.3.0",
"milliparsec": "2.2.1",
- "slam-types": "git://github.com/jantuomi/slam-types.git#441a72c",
+ "slam-types": "git://github.com/jantuomi/slam-types.git#9de4a1e",
"tmp": "0.2.1",
"tsm": "2.2.1"
},
@@ -2910,7 +2910,7 @@
},
"node_modules/slam-types": {
"version": "1.0.0",
- "resolved": "git+ssh://git@github.com/jantuomi/slam-types.git#441a72c04cfc61dfead5cad37202a1da87a44499",
+ "resolved": "git+ssh://git@github.com/jantuomi/slam-types.git#9de4a1ee520063025a9b2cd592a364e28cdd24dc",
"license": "ISC"
},
"node_modules/slash": {
@@ -5265,8 +5265,8 @@
"dev": true
},
"slam-types": {
- "version": "git+ssh://git@github.com/jantuomi/slam-types.git#441a72c04cfc61dfead5cad37202a1da87a44499",
- "from": "slam-types@git://github.com/jantuomi/slam-types.git#441a72c"
+ "version": "git+ssh://git@github.com/jantuomi/slam-types.git#9de4a1ee520063025a9b2cd592a364e28cdd24dc",
+ "from": "slam-types@git://github.com/jantuomi/slam-types.git#9de4a1e"
},
"slash": {
"version": "3.0.0",
diff --git a/package.json b/package.json
index dab0e1a..d139504 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,7 @@
"@tinyhttp/cors": "2.0.0",
"@tinyhttp/logger": "1.3.0",
"milliparsec": "2.2.1",
- "slam-types": "git://github.com/jantuomi/slam-types.git#441a72c",
+ "slam-types": "git://github.com/jantuomi/slam-types.git#9de4a1e",
"tmp": "0.2.1",
"tsm": "2.2.1"
},
diff --git a/src/index.ts b/src/index.ts
index 88a9a14..af61d0f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -7,6 +7,7 @@ import tmp from "tmp"
import fs from "fs"
import { RunnerApi } from "slam-types"
import { cors } from "@tinyhttp/cors"
+import { hrtime } from "process"
const exec = promisify(cb_exec)
const app = new App()
@@ -40,13 +41,20 @@ app
return res.sendStatus(400)
}
+ const apiTimeHandle = hrtime()
const { name: sourceFile } = tmp.fileSync() as { name: string }
fs.writeFileSync(sourceFile, body.source)
-
+ const executionTimeHandle = hrtime()
const result = await interpretFile(sourceFile)
- fs.rmSync(sourceFile)
+ const executionTime = Math.round(hrtime(executionTimeHandle)[1] / 1000)
+ fs.rm(sourceFile, () => void 0)
+ const apiTime = Math.round(hrtime(apiTimeHandle)[1] / 1000)
- const response: RunnerApi.SubmitResponse.Body = { result }
+ const response: RunnerApi.SubmitResponse.Body = {
+ result,
+ executionTime,
+ apiTime,
+ }
res.send(response)
})
.listen(PORT)