-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "async" API's for Odyssey to test out. #966
Conversation
734e1cf
to
c661108
Compare
Easy starting point for an Odyssey PR would be to create an async calling function in herbiejs.ts that uses the same strategy as |
c661108
to
a68914c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to merge this but we really need to do some cleanup here—lots of ugly duplicated code.
// -------------------------------------- | ||
|
||
// Sample | ||
const sampleStartData = await testAsyncAPI("sample-start", JSON.stringify({ formula: FPCoreFormula2, seed: 5 })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this body not stored in a variable above like all the others?
|
||
async function testAsyncAPI(endpointName, fetchBodyString) { | ||
const serverURL = `http://127.0.0.1:8000` | ||
const sampleStartURL = new URL(`${serverURL}${`/api/${endpointName}`}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const sampleStartURL = new URL(`${serverURL}${`/api/${endpointName}`}`) | |
const sampleStartURL = new URL(`${serverURL}/api/${endpointName}`) |
const rspJSON = await rsp.json() | ||
assertIdAndPath(rspJSON) | ||
|
||
const checkStatusURL = new URL(`${serverURL}${"/check-status/"}${rspJSON.job}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const checkStatusURL = new URL(`${serverURL}${"/check-status/"}${rspJSON.job}`) | |
const checkStatusURL = new URL(`${serverURL}/check-status/${rspJSON.job}`) |
let counter = 0 | ||
let cap = 100 | ||
let checkStatus = await fetch(checkStatusURL, { method: 'GET' }) | ||
// Loop to wait for for job to finnish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Loop to wait for for job to finnish | |
// Loop to wait for for job to finish |
Big fan of the Finns but not like this.
await new Promise(r => setTimeout(r, 100)); // ms | ||
} | ||
assert.equal(checkStatus.statusText, 'Job complete') | ||
const resultsURL = new URL(`${serverURL}${"/api/results/"}${rspJSON.job}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const resultsURL = new URL(`${serverURL}${"/api/results/"}${rspJSON.job}`) | |
const resultsURL = new URL(`${serverURL}/api/results/${rspJSON.job}`) |
[("api" "sample") #:method "post" sample-endpoint] | ||
[("api" "sample-start") #:method "post" sample-start-endpoint] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, these are all fine, it's not the end of the world or anything, but I think it would be a lot nicer to do /api/start/foo
instead of /api/foo-start
. We already have a separator character!
(define analyze-start-endpoint | ||
(post-with-json-response (lambda (post-data) | ||
(define formula-str (hash-ref post-data 'formula)) | ||
(define formula (read-syntax 'web (open-input-string formula-str))) | ||
(define sample (hash-ref post-data 'sample)) | ||
(define seed (hash-ref post-data 'seed #f)) | ||
(define test (parse-test formula)) | ||
(define pcontext (json->pcontext sample (test-context test))) | ||
(define command | ||
(create-job 'errors | ||
test | ||
#:seed seed | ||
#:pcontext pcontext | ||
#:profile? #f | ||
#:timeline-disabled? #t)) | ||
(define job-id (start-job command)) | ||
(hasheq 'job job-id 'path (make-path job-id))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be convinced to merge this but surely this is extremely duplicative with the existing non-async endpoints? Could we have a single function and then generic wrappers around it to make it sync or async?
a68914c
to
bf8dce5
Compare
bf8dce5
to
6bdd26c
Compare
Replaced by PR #983. |
This PR duplicates the API's Currently used by Odyessey to have a different async calling pattern. Where you start the job and then can use
check-status
to see if the job has been completed then use a newresults
API to retrieve the information.While I'm not sure if the async version of the API is a value add this didn't take long to add and allows for flexibility to experiment with how Odyessy manages jobs sent to Herbie as this has been talked about as one possible advantage of the new server design. However, I do think the
results
API could be useful for re-retrieving information from a job you know has been completed.An example of how to call these new API's can be found in the
testAsyncAPI
function in the updatedtestApi.mjs
file.Very open to different API names as I just copied the convention that
improve
andimprove-start
used.Let me know your thoughts and if I should make a PR in Odyessy using these new APIs.