Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix log level for async queries #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading