Skip to content

Commit

Permalink
Merge pull request #21 from biothings/kg-refactor
Browse files Browse the repository at this point in the history
Send MetaKG to threads
  • Loading branch information
tokebe committed May 21, 2024
2 parents dd3eb20 + ba2faa8 commit 9512f12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/controllers/cron/update_local_smartapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import validUrl from "valid-url";
import SMARTAPI_EXCLUSIONS from "../../config/smartapi_exclusions";
import getSmartApiOverrideConfig from "../../config/smartapi_overrides";
import { SmartApiOverrides } from "../../types";
import apiList from "../../config/api_list";
import MetaKG, { SmartAPISpec } from "@biothings-explorer/smartapi-kg";
import { redisClient } from "@biothings-explorer/utils";

const userAgent = `BTE/${process.env.NODE_ENV === "production" ? "prod" : "dev"} Node/${process.version} ${
process.platform
Expand Down Expand Up @@ -325,7 +328,13 @@ async function updateSmartAPISpecs() {
await fs.writeFile(localFilePath, JSON.stringify({ hits: hits }));
const predicatesInfo = await getOpsFromPredicatesEndpoints(res.data.hits);
await fs.writeFile(predicatesFilePath, JSON.stringify(predicatesInfo));
}

// Create a new metakg
const metakg = new MetaKG();
metakg.constructMetaKGSync(true, { predicates: predicatesInfo, smartapiSpecs: { hits: hits as any }, apiList });
global.metakg = metakg;
global.smartapi = { hits };
};

async function getAPIOverrides(data: { total?: number; hits: any }, overrides: SmartApiOverrides) {
// if only_overrides is enabled, only overridden apis are used
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/threading/threadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Telemetry } from "@biothings-explorer/utils";
import ErrorHandler from "../../middlewares/error";
import { Request, Response } from "express";
import { BullJob, PiscinaWaitTime, ThreadPool } from "../../types";
import { TaskInfo, InnerTaskData } from "@biothings-explorer/types";
import { TaskInfo, InnerTaskData, QueryHandlerOptions } from "@biothings-explorer/types";
import { DialHome, TrapiQuery, TrapiResponse } from "@biothings-explorer/types";
import { Queue } from "bull";

Expand Down Expand Up @@ -111,6 +111,7 @@ async function queueTaskToWorkers(pool: Piscina, taskInfo: TaskInfo, route: stri
const { traceparent, tracestate } = otelData;

const taskData: InnerTaskData = { req: taskInfo, route, traceparent, tracestate, port: toWorker };
taskData.req.data.options = {...taskData.req.data.options, metakg: global.metakg?.ops, smartapi: global.smartapi} as QueryHandlerOptions;

// Propagate data between task runner and bull job
if (job) taskData.job = { jobId: job.id, queueName: job.queue.name };
Expand Down

0 comments on commit 9512f12

Please sign in to comment.