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

Search #2190

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft

Search #2190

wants to merge 12 commits into from

Conversation

ccollie
Copy link
Contributor

@ccollie ccollie commented Sep 22, 2023

Adds job search functionality using mongo syntax.

Copy link
Collaborator

@roggervalf roggervalf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need also a new section in our docs for this feature. I didn't review so deeper but it looks like a good beginning for this feature. I'll revisit it

const trace = currentJob['stacktrace'];
if (!Array.isArray(trace)) {
if (typeof trace === 'string') {
currentJob['stacktrace'] = JSON.parse(trace);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious about this logic, https://github.com/taskforcesh/bullmq/blob/master/src/classes/job.ts#L316 fromJSON method is handling stacktrace values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely be better if we could just use Job.fromJson here.

const raw = currentJob as JobJsonRaw;
const job = Job.fromJSON(queue, raw, jobId);
const ts = currentJob['timestamp'];
job.timestamp = ts ? parseInt(ts) : Date.now();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type(val) == 'table'
end

local function isArray(t)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use includes to split this command as it's kind of big

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I also intend to split out state list iteration methods using lua's pairs prrotocol.

Copy link
Contributor

@manast manast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive job overall. I could not review in detail all the .lua code, I will try to spend more time analyzing it as the PR is more ready.
A couple of remarks:

  • This script can potentially put a lot of pressure on Redis, as it will be CPU intensive. I think it should be wise to try to move as much logic as possible to the JS side. Maybe preprocess the query so that the job to do on lua side would be minimal. A crazy extreme of this would actually be to generate the lua code in JS that actually is used to check every job and then use something like this: https://www.lua.org/manual/5.1/manual.html#pdf-loadstring
  • The method must allow to limit for amount of returned jobs per call, and also the amount of jobs to test for. As without any of these two constraints the call to this script could potentially hang the Redis server for too long. More than 100ms per call will probably be too slow in practice.

@@ -355,6 +355,15 @@ export class QueueGetters<
);
}

async getJobsByFilter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the typedoc style documentation for this public method.

const trace = currentJob['stacktrace'];
if (!Array.isArray(trace)) {
if (typeof trace === 'string') {
currentJob['stacktrace'] = JSON.parse(trace);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely be better if we could just use Job.fromJson here.

['id'] = 1,
}

local JsType = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that JsType should use the same name convention as the rest of the constants. Or the rest of the constant the same convention as JsType 😅

}
}

for (let i = 1; i < response.length; i += 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so the thing that makes this code more complex seems to be that all the jobs are returned flattened in one single array. Wouldn't be better to return an array of arrays from the lua script so that we could have much simpler code here?

for _, jobId in pairs(scannedJobIds) do

local jobIdKey = keyPrefix .. jobId
local jobHash = redis.pcall('HGETALL', jobIdKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could just restrict the search to the "data" field.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we later need all the fields of the job, if we assume the search would just match a narrow set of jobs, it would be more efficient to read the remaining fields only for the jobs that actually match the search.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The code actually collects the fields that are accessed in the query so that's possible with not too much problem.

@OrionWambert
Copy link

Any update ?

@ccollie
Copy link
Contributor Author

ccollie commented Feb 23, 2024

@OrionWambert Ping me. I may make some time over the weekend to pick this back up.

@bfbechlin
Copy link

Any news on this topic? @manast @roggervalf It would be extremely helpful to have a wildcard search on jobs based on id, data and logs or even only in the id to start with. Awesome project btw, congratz 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants