-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update team and api metakg endpoints to use globally loaded grap…
…h in async fashion
- Loading branch information
1 parent
1e3f83d
commit 6518716
Showing
3 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
import handler from "../../controllers/meta_knowledge_graph"; | ||
import * as utils from "../../utils/common"; | ||
import path from "path"; | ||
import { TaskInfo } from "@biothings-explorer/types"; | ||
import { runTask, taskResponse, taskError } from "../../controllers/threading/threadHandler"; | ||
import { Express, NextFunction, Request, Response, RequestHandler } from "express"; | ||
|
||
import MetaKnowledgeGraph from "@biothings-explorer/smartapi-kg"; | ||
|
||
class MetaKGByAPI { | ||
setRoutes(app: Express) { | ||
app | ||
.route("/v1/smartapi/:smartapiID/meta_knowledge_graph") | ||
.route("/v1/smartapi/:smartAPIID/meta_knowledge_graph") | ||
.get((async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const metaKGHandler = new handler(req.params.smartapiID); | ||
const kg = await metaKGHandler.getKG(); | ||
const response = await runTask(req, res, path.parse(__filename).name); | ||
res.setHeader("Content-Type", "application/json"); | ||
res.end(JSON.stringify(kg)); | ||
res.end(JSON.stringify(response)); | ||
} catch (error) { | ||
next(error); | ||
} | ||
})as RequestHandler) | ||
.all(utils.methodNotAllowed); | ||
} | ||
|
||
async task(taskInfo: TaskInfo) { | ||
try { | ||
const metaKGHandler = new handler(taskInfo.data.smartAPIID, undefined); | ||
let metakg = undefined; | ||
// initialize MetaKG only if ops are provided because handler logic is built upon that | ||
if (taskInfo.data.options.metakg_ops !== undefined) | ||
metakg = new MetaKnowledgeGraph(undefined, undefined, taskInfo.data.options.metakg_ops); | ||
const kg = await metaKGHandler.getKG(metakg); | ||
// response.logs = utils.filterForLogLevel(response.logs, options.logLevel); | ||
return taskResponse(kg); | ||
} catch (error) { | ||
taskError(error as Error); | ||
} | ||
} | ||
} | ||
|
||
export default new MetaKGByAPI(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
import handler from "../../controllers/meta_knowledge_graph"; | ||
import path from "path"; | ||
import { TaskInfo } from "@biothings-explorer/types"; | ||
import * as utils from "../../utils/common"; | ||
import { runTask, taskResponse, taskError } from "../../controllers/threading/threadHandler"; | ||
import { Express, NextFunction, Request, Response, RequestHandler } from "express"; | ||
|
||
import MetaKnowledgeGraph from "@biothings-explorer/smartapi-kg"; | ||
|
||
class MetaKGByTeam { | ||
setRoutes(app: Express) { | ||
app | ||
.route("/v1/team/:teamName/meta_knowledge_graph") | ||
.get((async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const metaKGHandler = new handler(undefined, req.params.teamName); | ||
const kg = await metaKGHandler.getKG(); | ||
const response = await runTask(req, res, path.parse(__filename).name); | ||
res.setHeader("Content-Type", "application/json"); | ||
res.end(JSON.stringify(kg)); | ||
res.end(JSON.stringify(response)); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}) as RequestHandler) | ||
.all(utils.methodNotAllowed); | ||
} | ||
|
||
async task(taskInfo: TaskInfo) { | ||
try { | ||
const metaKGHandler = new handler(undefined, taskInfo.data.teamName); | ||
let metakg = undefined; | ||
// initialize MetaKG only if ops are provided because handler logic is built upon that | ||
if (taskInfo.data.options.metakg_ops !== undefined) | ||
metakg = new MetaKnowledgeGraph(undefined, undefined, taskInfo.data.options.metakg_ops); | ||
const kg = await metaKGHandler.getKG(metakg); | ||
// response.logs = utils.filterForLogLevel(response.logs, options.logLevel); | ||
return taskResponse(kg); | ||
} catch (error) { | ||
taskError(error as Error); | ||
} | ||
} | ||
} | ||
|
||
export default new MetaKGByTeam(); |