Skip to content

Commit

Permalink
fix: typings
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Mar 22, 2024
1 parent 97ba040 commit c67c709
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/controllers/threading/threadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { tasks } from "../../routes/index";
import { Telemetry } from "@biothings-explorer/utils";
import ErrorHandler from "../../middlewares/error";
import { Request, Response } from "express";
import { AsyncResultSummary, BullJob, PiscinaWaitTime, ThreadPool } from "../../types";
import { BullJob, PiscinaWaitTime, ThreadPool } from "../../types";
import { TaskInfo, InnerTaskData } from "@biothings-explorer/types";
import { DialHome, TrapiQuery, TrapiResponse } from "@biothings-explorer/types";
import { Queue } from "bull";
Expand Down Expand Up @@ -237,7 +237,7 @@ export async function runTask(req: Request, res: Response, route: string, useBul

if (process.env.USE_THREADING === "false") {
// Threading disabled, just use the provided function in main event loop
const response = await tasks[route](taskInfo);
const response = await tasks[route](taskInfo) as TrapiResponse;
return response;
} else if (!(queryQueue && useBullSync)) {
// Redis unavailable or query not to sync queue such as asyncquery_status
Expand Down Expand Up @@ -311,7 +311,7 @@ export async function runTask(req: Request, res: Response, route: string, useBul

export async function runBullJob(job: BullJob, route: string, useAsync = true) {
const taskInfo: TaskInfo = {
id: job.id,
id: String(job.id),
data: { ...job.data },
};
const response = await queueTaskToWorkers(
Expand Down
12 changes: 2 additions & 10 deletions src/routes/v1/asyncquery_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ import { runTask, taskResponse, taskError } from "../../controllers/threading/th
import Debug from "debug";
const debug = Debug("bte:biothings-explorer-trapi:async");
import { Express, NextFunction, Request, RequestHandler, Response } from "express";
import {
NonTrapiAsyncAltResponse,
QueueData,
TaskInfo,
TrapiAsyncStatusResponse,
TrapiLog,
TrapiQuery,
TrapiResponse,
} from "@biothings-explorer/types";
import { TaskInfo, TrapiAsyncStatusResponse, TrapiLog, TrapiResponse } from "@biothings-explorer/types";
import { BteRoute } from "../../types";
import { Queue } from "bull";
import StatusError from "../../utils/errors/status_error";
Expand Down Expand Up @@ -109,7 +101,7 @@ class V1CheckQueryStatus implements BteRoute {
const storedResponse = await getQueryResponse(jobID, taskInfo.data.options.logLevel);

if (storedResponse && !("logs" in storedResponse) && logs) {
(storedResponse as NonTrapiAsyncAltResponse).logs = logs;
(storedResponse as Partial<TrapiAsyncStatusResponse>).logs = logs;
}

let returnValue: TrapiResponse | TrapiAsyncStatusResponse;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { URL } from "url";
import yaml2json from "js-yaml";
import fs from "fs/promises";
import path from "path";
import { TrapiLog, TrapiWorkflow } from "@biothings-explorer/types";
import { TrapiLog, TrapiSchema, TrapiWorkflow } from "@biothings-explorer/types";
import { NextFunction, Request, Response } from "express";

const schema: unknown[] = [];

export async function getSchema() {
if (schema.length !== 0) return schema[0];
export async function getSchema(): Promise<TrapiSchema> {
if (schema.length !== 0) return schema[0] as TrapiSchema;
schema.push(
yaml2json.load(await fs.readFile(path.join(__dirname, "../../docs/smartapi.yaml"), { encoding: "utf8" })),
);
// console.log(schema);
return schema[0];
return schema[0] as TrapiSchema;
}

export function removeQuotesFromQuery(queryString: string) {
Expand Down

0 comments on commit c67c709

Please sign in to comment.