Skip to content

Commit

Permalink
fix: async data type consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Apr 4, 2024
1 parent e573d07 commit 4ada577
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
"@types/js-yaml": "^4.0.8",
"@types/jsonata": "^1.5.1",
"@types/lodash": "^4.14.200",
"@types/lz4": "^0.6.4",
"@types/node": "^20.8.7",
"@types/pascal-case": "^1.1.2",
"@types/stream-json": "^1.7.7",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
Expand Down
7 changes: 3 additions & 4 deletions src/controllers/async/asyncquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { Telemetry } from "@biothings-explorer/utils";
import ErrorHandler from "../../middlewares/error";
import { Request, Response, NextFunction } from "express";
import { Queue } from "bull";
import { TrapiQueryGraph, TrapiResponse } from "@biothings-explorer/types";
import { QueueData, TrapiQueryGraph, TrapiResponse } from "@biothings-explorer/types";
import TRAPIQueryHandler from "@biothings-explorer/query_graph_handler";
import StatusError from "../../utils/errors/status_error";

export async function asyncquery(
req: Request,
res: Response,
next: NextFunction,
queueData, // TODO: type
queueData: QueueData,
queryQueue: Queue,
): Promise<void> {
try {
Expand All @@ -46,7 +46,6 @@ export async function asyncquery(
{ ...queueData, url: url.replace("status", "response") },
{
jobId: jobId,
url: url,
timeout: parseInt(process.env.JOB_TIMEOUT ?? (1000 * 60 * 5).toString()),
removeOnFail: {
age: 24 * 60 * 60, // keep failed jobs for a day (in case user needs to review fail reason)
Expand Down Expand Up @@ -84,7 +83,7 @@ async function storeQueryResponse(jobID: string, response: TrapiResponse | undef
let i = 0;
input
.pipe(chunker(10000000, { flush: true }))
.on("data", async chunk => {
.on("data", async (chunk: Buffer) => {
await redisClient.client.hsetTimeout(
`asyncQueryResult:${jobID}:${key}`,
String(i++),
Expand Down
1 change: 1 addition & 0 deletions src/routes/v1/asyncquery_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class V1AsyncQuery implements BteRoute {
next: NextFunction,
) => {
const queueData: QueueData = {
route: req.route.path,
queryGraph: req.body.message.query_graph,
workflow: req.body.workflow,
callback_url: req.body.callback,
Expand Down
5 changes: 3 additions & 2 deletions src/routes/v1/asyncquery_v1_by_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const predicatesPath = path.resolve(
__dirname,
process.env.STATIC_PATH ? `${process.env.STATIC_PATH}/data/predicates.json` : "../../../data/predicates.json",
);
import { Express, NextFunction, Request, RequestHandler, Response } from "express";
import { QueueData, TaskInfo, TrapiQuery } from "@biothings-explorer/types";
import { Express, NextFunction, Request, Response } from "express";
import { QueueData, TaskInfo } from "@biothings-explorer/types";
import { BteRoute } from "../../types";

class V1AsyncQueryByAPI implements BteRoute {
Expand All @@ -23,6 +23,7 @@ class V1AsyncQueryByAPI implements BteRoute {
.route("/v1/smartapi/:smartapi_id/asyncquery")
.post(swaggerValidation.validate, async (req: Request, res: Response, next: NextFunction) => {
const queueData: QueueData = {
route: req.route.path,
queryGraph: req.body.message.query_graph,
smartAPIID: req.params.smartapi_id,
workflow: req.body.workflow,
Expand Down
9 changes: 4 additions & 5 deletions src/routes/v1/asyncquery_v1_by_team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@ const predicatesPath = path.resolve(
);

import { Express, NextFunction, Request, RequestHandler, Response } from "express";
import { QueueData, TaskInfo, TrapiQuery, TrapiQueryGraph } from "@biothings-explorer/types";
import { QueueData, TaskInfo } from "@biothings-explorer/types";

class V1AsyncQueryByTeam {
class V1AsyncQueryByTeam implements BteRoute {
setRoutes(app: Express) {
app
.route("/v1/team/:team_name/asyncquery")
.post(swaggerValidation.validate, (async (req: Request, res: Response, next: NextFunction) => {
const queueData = {
const queueData: QueueData = {
route: req.route.path,
queryGraph: req.body.message.query_graph,
teamName: req.params.team_name,
logLevel: req.body.log_level,
workflow: req.body.workflow,
callback_url: req.body.callback,
options: {
logLevel: req.body.log_level,
submitter: req.body.submitter,
...req.query,
},
enableIDResolution: true,
};
await asyncquery(req, res, next, queueData, global.queryQueue["bte_query_queue_by_team"]);
}) as RequestHandler)
Expand Down

0 comments on commit 4ada577

Please sign in to comment.