From bbb4600b337e41076b6f4ebe7b407e0b4e84caf2 Mon Sep 17 00:00:00 2001 From: Rohan Juneja Date: Mon, 13 Nov 2023 18:50:38 -0800 Subject: [PATCH] fix log level for async queries --- src/controllers/threading/threadHandler.js | 2 +- src/routes/v1/asyncquery_status.js | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/controllers/threading/threadHandler.js b/src/controllers/threading/threadHandler.js index 17673176..f93772f6 100644 --- a/src/controllers/threading/threadHandler.js +++ b/src/controllers/threading/threadHandler.js @@ -187,7 +187,7 @@ async function runTask(req, task, route, res, useBullSync = true) { queryGraph: req.body.message?.query_graph, workflow: req.body.workflow, options: { - logLevel: req.body.log_level, + logLevel: req.body.log_level ?? req.query.log_level, submitter: req.body.submitter, smartAPIID: req.params.smartapi_id, teamName: req.params.team_name, diff --git a/src/routes/v1/asyncquery_status.js b/src/routes/v1/asyncquery_status.js index ee4de9ce..6c87b1ca 100644 --- a/src/routes/v1/asyncquery_status.js +++ b/src/routes/v1/asyncquery_status.js @@ -51,8 +51,16 @@ class VCheckQueryStatus { } await queryQueue.isReady(); const state = await job.getState(); - let logs = await queryQueue.getJobLogs(job_id); - logs = logs.logs.map(log => JSON.parse(log)); + let unfilteredLogs = await queryQueue.getJobLogs(job_id); + + // filter logs + let filteredLogs = { logs: unfilteredLogs?.logs?.map(log => JSON.parse(log)) } + + if ((job.data.options.logLevel || req.data.options.logLevel) && filteredLogs.logs) { + utils.filterForLogLevel(filteredLogs, req.data.options.logLevel ?? job.data.options.logLevel) + } + let logs = filteredLogs.logs; + let [status, description] = { // convert to TRAPI states completed: ["Completed", "The query has finished executing."], @@ -64,7 +72,8 @@ class VCheckQueryStatus { stuck: ["Failed", "The query is stuck (if you see this, raise an issue)."], null: ["Failed", "The query status is unknown, presumed failed (if you see this, raise an issue)."], }[state]; - let progress = job._progress; + let progress = job._progress; + if (status === "Failed" && !req.endpoint.includes("asyncquery_response")) { if (description.includes("Promise timed out")) { // something might break when calculating process.env.JOB_TIMEOUT so wrap it in try catch @@ -87,7 +96,7 @@ class VCheckQueryStatus { // If done, just give response if using the response_url if ((state === "completed" || state === "failed") && req.endpoint.includes("asyncquery_response")) { let returnValue; - const storedResponse = await getQueryResponse(job_id, req.data.options.logLevel); + const storedResponse = await getQueryResponse(job_id, req.data.options.logLevel ?? job.data.options.logLevel); if (!storedResponse.logs && logs) { storedResponse.logs = logs;