Skip to content

Commit

Permalink
Merge pull request #23 from biothings/workflow-id
Browse files Browse the repository at this point in the history
Use correct workflow id conditionally
  • Loading branch information
tokebe committed Apr 12, 2024
2 parents 13f2834 + 6eb4390 commit 4b89202
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/controllers/async/asyncquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export async function asyncqueryResponse(
status: "Failed",
schema_version: global.SCHEMA_VERSION,
biolink_version: global.BIOLINK_VERSION,
workflow: [{ id: "lookup" }],
workflow: [{ id: handler.options.teamName || handler.options.smartAPIID ? "lookup" : "lookup_and_score" }],
description: (e as Error).toString(),
trace: process.env.NODE_ENV === "production" ? undefined : (e as Error).stack,
logs: handler.logs,
Expand Down
17 changes: 13 additions & 4 deletions src/controllers/async/asyncquery_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,35 @@ export function getQueryQueue(name: string): BullQueue {
}

global.queryQueue[name] = new Queue(name, process.env.REDIS_HOST ?? "redis://127.0.0.1:6379", details)
.on("error", function(error) {
.on("error", function (error) {
console.log("err", error);
})
.on("failed", async function(job: BullJob, error) {
.on("failed", async function (job: BullJob, error) {
debug(`Async job ${job.id} failed with error ${error.message}`);
try {
job.data.abortController.abort();
} catch (error) {
debug(error);
}
if (job.data.callback_url) {
const logs: TrapiLog[] = await global.queryQueue[name]?.getJobLogs(job.id)?.logs?.map((log: string) => JSON.parse(log));
const logs: TrapiLog[] = await global.queryQueue[name]
?.getJobLogs(job.id)
?.logs?.map((log: string) => JSON.parse(log));
try {
await axios({
method: "post",
url: job.data.callback_url,
data: {
schema_version: global.SCHEMA_VERSION,
biolink_version: global.BIOLINK_VERSION,
workflow: [{ id: "lookup" }],
workflow: [
{
id:
job.data.route.includes(":smartapi_id") || job.data.route.includes(":team_name")
? "lookup"
: "lookup_and_score",
},
],
logs: logs,
message: {
query_graph: job.data.queryGraph,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/cron/update_local_smartapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function getPredicatesFromGraphData(predicate_endpoint: string, data) {

const addNewPredicates = edge => {
if (edge.knowledge_types && Array.isArray(edge.knowledge_types)) {
if (!edge.knowledge_types.includes("lookup")) {
if (!(edge.knowledge_types.includes("lookup"))) {
return;
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/controllers/meta_knowledge_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,21 @@ export default class MetaKnowledgeGraphHandler {
object: output,
qualifiers: pred.qualifiers
? Object.entries(pred.qualifiers).map(([qual, val]) => {
if (!Array.isArray(val)) {
const [type_id, value] = this._modifyQualifierData(qual, val);
return { qualifier_type_id: type_id, applicable_values: [value] };
} else {
let type_id = this._modifyPredicate(qual);
let values = [];
val.forEach(curVal => {
const [_, value] = this._modifyQualifierData(qual, curVal);
values.push(value);
});
return { qualifier_type_id: type_id, applicable_values: values };
}
})
if (!Array.isArray(val)) {
const [type_id, value] = this._modifyQualifierData(qual, val);
return { qualifier_type_id: type_id, applicable_values: [value] };
} else {
let type_id = this._modifyPredicate(qual);
let values = [];
val.forEach(curVal => {
const [_, value] = this._modifyQualifierData(qual, curVal);
values.push(value);
});
return { qualifier_type_id: type_id, applicable_values: values };
}
})
: undefined,
knowledge_types: ["lookup"],
knowledge_types: this.smartAPIID || this.teamName ? ["lookup"] : ["lookup_and_score"],
};
knowledge_graph.edges.push(edge);
edges[`${input}-${pred.predicate}-${output}`] = edge;
Expand Down Expand Up @@ -222,9 +222,9 @@ export default class MetaKnowledgeGraphHandler {
object,
qualifiers: qualifiers
? Object.entries(qualifiers).map(([qual, val]) => {
const [type_id, value] = this._modifyQualifierData(qual, val);
return { qualifier_type_id: type_id, applicable_values: [value] };
})
const [type_id, value] = this._modifyQualifierData(qual, val);
return { qualifier_type_id: type_id, applicable_values: [value] };
})
: undefined,
knowledge_types: ["inferred"],
};
Expand Down
4 changes: 2 additions & 2 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function validateWorkflow(workflow: TrapiWorkflow[] | unknown) {
if (workflow === undefined) {
return;
}
if (!Array.isArray(workflow) || workflow.length !== 1 || workflow[0].id !== "lookup") {

if (!Array.isArray(workflow) || workflow.length !== 1 || !["lookup", "lookup_and_score"].includes(workflow[0].id)) {
throw new WorkflowError("BTE doesn't handle the operations specified in the workflow field.");
}
}
Expand Down Expand Up @@ -63,4 +64,3 @@ export function filterForLogLevel(logs: TrapiLog[], logLevel: string) {
export function methodNotAllowed(_req: Request, res: Response, _next: NextFunction) {
res.status(405).send();
}

0 comments on commit 4b89202

Please sign in to comment.