Skip to content

Commit

Permalink
Merge branch 'main' into fix-224
Browse files Browse the repository at this point in the history
  • Loading branch information
colleenXu committed Nov 8, 2021
2 parents 993888b + 07ca3e6 commit 5f263be
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 18 deletions.
3 changes: 2 additions & 1 deletion __test__/integration/routes/v1query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const request = require('supertest');
const fs = require("fs");
var path = require('path');

// Reason: Takes too long as predict, missing smartapi.yaml for validation
describe("Testing /v1/query endpoints", () => {
const invalid_example_folder = path.resolve(__dirname, "../../../examples/v1.1/invalid");
const example_folder = path.resolve(__dirname, '../../../examples/v1.1');
Expand Down Expand Up @@ -60,7 +61,7 @@ describe("Testing /v1/query endpoints", () => {
})
})

test("Multi-hop query results should have combined edges", async () => {
test.skip("Multi-hop query results should have combined edges", async () => {
const query = JSON.parse(fs.readFileSync(path.join(example_folder, "query_multihop_gene_gene_chemical.json")));
await request(app)
.post("/v1/query")
Expand Down
7 changes: 4 additions & 3 deletions __test__/integration/routes/v1query_by_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ describe("Testing /v1/smartapi/{smartapi_id}/query endpoints", () => {
.expect(200)
.expect('Content-Type', /json/)
.then(response => {
expect(response.body.message.knowledge_graph.nodes).toHaveProperty("UniProtKB:O15554")
expect(Object.keys(response.body.message.knowledge_graph.nodes)).toContain("PUBCHEM.COMPOUND:5070")
})
})

test("Query to Text Mining Co-occurrence KP should be correctly paginated", async () => {
// Reason: TypeError: Cannot set property attributes of #<IrresolvableBioEntity> which has only a getter
test.skip("Query to Text Mining Co-occurrence KP should be correctly paginated", async () => {
const query = JSON.parse(fs.readFileSync(path.join(example_folder, "textmining/query_chemicals_related_to_disease.json")));
const apiResponse = await axios.get('https://biothings.ncats.io/text_mining_co_occurrence_kp/query?q=object.id:%22MONDO:0005252%22%20AND%20subject.type:%22ChemicalSubstance%22');
const apiResponse = await axios.get('https://biothings.ncats.io/text_mining_co_occurrence_kp/query?q=object.id:%22MONDO:0005252%22%20AND%20subject.type:%22SmallMolecule%22');
const hits = apiResponse.data.total;
await request(app)
.post("/v1/smartapi/5be0f321a829792e934545998b9c6afe/query/")
Expand Down
5 changes: 3 additions & 2 deletions __test__/integration/routes/v1query_by_team.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ describe("Testing /v1/team/{team_name}/query endpoints", () => {
})
})

test("Query to Text Mining Co-occurrence KP should be correctly paginated", async () => {
// Reason: TypeError: Cannot set property attributes of #<IrresolvableBioEntity> which has only a getter
test.skip("Query to Text Mining Co-occurrence KP should be correctly paginated", async () => {
const query = JSON.parse(fs.readFileSync(path.join(example_folder, "textmining/query_chemicals_related_to_disease.json")));
const apiResponse = await axios.get('https://biothings.ncats.io/text_mining_co_occurrence_kp/query?q=object.id:%22MONDO:0005252%22%20AND%20subject.type:%22ChemicalSubstance%22');
const apiResponse = await axios.get('https://biothings.ncats.io/text_mining_co_occurrence_kp/query?q=object.id:%22MONDO:0005252%22%20AND%20subject.type:%22SmallMolecule%22');
const hits = apiResponse.data.total;
await request(app)
.post("/v1/team/Text Mining Provider/query/")
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/asyncquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports.asyncqueryResponse = async (handler, callback_url) => {
let response = null
let callback_response = null;
try{
await handler.query_2();
await handler.query();
response = handler.getResponse();
}catch (e){
console.error(e)
Expand Down
4 changes: 3 additions & 1 deletion src/middlewares/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class ErrorHandler {
more_info: error.errors
});
}
if (error instanceof QueryGraphHandler.InvalidQueryGraphError) {
// read stack when instance or err is broken
if (error instanceof QueryGraphHandler.InvalidQueryGraphError ||
error.stack.includes("InvalidQueryGraphError")) {
return res.status(400).json({
error: "Your input query graph is invalid",
more_info: error.message
Expand Down
6 changes: 5 additions & 1 deletion src/middlewares/validate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const swaggerValidation = require('openapi-validator-middleware');
const path = require('path');

const schema = path.join(__dirname, '../../docs/smartapi.yaml');

const inputValidationOptions = {
formats: [
{ name: 'double', pattern: /\d+(\.\d+)?/ },
Expand All @@ -15,6 +19,6 @@ const inputValidationOptions = {
//firstError: true,
expectFormFieldsInBody: true
};
swaggerValidation.init("docs/smartapi.yaml", inputValidationOptions);
swaggerValidation.init(schema, inputValidationOptions);

module.exports = swaggerValidation;
6 changes: 6 additions & 0 deletions src/routes/v1/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ exports.API_LIST = [
{
id: '9dd890397a7b8d98fbe247d56cac2b8f',
name: 'ICEES DILI Instance API'
},
// notes on ICEES:
// - don't ingest the COVID APIs (they may be broken / not actively developed)
{
id: '855adaa128ce5aa58a091d99e520d396',
name: 'Connections Hypothesis Provider API'
},
// notes on ICEES:
// - don't ingest the COVID APIs (they may be broken / not actively developed)
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v1/query_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RouteQueryTest {
const queryGraph = req.body.message.query_graph;
const handler = new TRAPIGraphHandler.TRAPIQueryHandler({}, smartAPIPath, undefined, false);
handler.setQueryGraph(queryGraph);
await handler.query_2();
await handler.query();
parentPort.postMessage({msg: handler.getResponse()});
} catch (error) {
parentPort.postMessage({err: error});
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v1/query_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class V1RouteQuery {
predicatesPath,
);
handler.setQueryGraph(queryGraph);
await handler.query_2();
await handler.query();

parentPort.postMessage({msg: handler.getResponse()});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v1/query_v1_by_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RouteQueryV1ByAPI {
false
);
handler.setQueryGraph(queryGraph);
await handler.query_2();
await handler.query();
parentPort.postMessage({msg: handler.getResponse()});
} catch (error) {
parentPort.postMessage({err: error});
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v1/query_v1_by_team.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RouteQueryV1ByTeam {
false
);
handler.setQueryGraph(queryGraph);
await handler.query_2();
await handler.query();
parentPort.postMessage({msg: handler.getResponse()});
} catch (error) {
parentPort.postMessage({err: error});
Expand Down
21 changes: 16 additions & 5 deletions src/utils/threadWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@ module.exports = function runWorker(task) {
const worker = new Worker(path.resolve(__dirname, "../server.js"), {
workerData: { req: task.req, route: task.route },
});
let reqDone, cacheDone = false;
let reqDone = false;
let cacheInProgress = 0;
worker.on("message", (...args) => {
const workerID = worker.threadId;
if (args[0].cacheInProgress) {
cacheInProgress += 1;
}
if (args[0].cacheDone) {
cacheDone = true;
} else {
if (typeof args[0].cacheDone === 'number') {
cacheInProgress -= args[0].cacheDone;
} else {
cacheInProgress = 0;
}
} else if (args[0].msg) {
reqDone = true;
resolve(...args);
}
if (reqDone && cacheDone) {
if (reqDone && cacheInProgress <= 0) {
worker.terminate().then(() => debug(`Worker thread ${workerID} completed task, terminated successfully.`));
}
});
worker.on("error", reject);
worker.on("error", (...args) => {
reqDone = true; // allows caching to finish if any was started.
reject(...args);
});
worker.on("exit", code => {
if (code !== 0) {
reject(new Error(`Worker ${worker.threadId} exited with code ${code}`));
Expand Down

0 comments on commit 5f263be

Please sign in to comment.