diff --git a/src/controllers/cron/update_local_smartapi.ts b/src/controllers/cron/update_local_smartapi.ts index b52a79b..502e806 100644 --- a/src/controllers/cron/update_local_smartapi.ts +++ b/src/controllers/cron/update_local_smartapi.ts @@ -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 @@ -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 diff --git a/src/controllers/threading/threadHandler.ts b/src/controllers/threading/threadHandler.ts index e62d232..7f91bb3 100644 --- a/src/controllers/threading/threadHandler.ts +++ b/src/controllers/threading/threadHandler.ts @@ -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"; @@ -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 };