Skip to content

Commit

Permalink
fix log level for async queries
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Nov 14, 2023
1 parent 842f67b commit bbb4600
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/controllers/threading/threadHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions src/routes/v1/asyncquery_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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."],
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit bbb4600

Please sign in to comment.