bull-board icon indicating copy to clipboard operation
bull-board copied to clipboard

Possibility to find a job in queue by it's ID

Open ammirator-administrator opened this issue 10 months ago • 10 comments

At the moment we have the list of all jobs in a queue separated in different tabs by it's status

But there is no possibility to find a job by it's ID and investigate it in case if needed Imagine having a platform even if small but which handles let's say 1000 jobs a day In that list it would be hard to go manually thru all and find the one you need

A small filter at the top would be super useful to find a job

ammirator-administrator avatar Apr 06 '24 11:04 ammirator-administrator

Hi, would you like to prepare a PR for this feature? I'll more than happy to review it 😉

felixmosh avatar Apr 06 '24 14:04 felixmosh

Hi, would you like to prepare a PR for this feature? I'll more than happy to review it 😉

Hello, I'd like to contribute to this project. Is there any project documentation that could help me quickly understand the architecture and add functionalities?

OrionWambert avatar Apr 08 '24 07:04 OrionWambert

Nope, just review the ui & api folders in packages

felixmosh avatar May 01 '24 15:05 felixmosh

There is already a route GET /api/queues/:queueName/:jobId. I think just a UI element calling this endpoint will work. Let me know if I am wrong @felixmosh

suyash-thakur avatar Jun 03 '24 05:06 suyash-thakur

Yeah, you are probably right... But it will return always one / zero result.

I prefer to implement a full search (once the underline lib will add it, vote for my request)

felixmosh avatar Jun 03 '24 05:06 felixmosh

At least by ID would be good as Initial step after this search may be extended and search by something else

I do not think that bullmq will add ever a fullsearch capability since it uses redis and to do something as full search with redis is hard

At the beginning it may be just by ID at least, since a lot of peoples just stores the IDs related to some job in a simple database so that they can cancel later or do some investigation if needed

ammirator-administrator avatar Jun 03 '24 17:06 ammirator-administrator

I agree. It's unlikely that bullmq will provide a fullsearch. To implement fullsearch from our side we will need to store the index in redis, if bullmq exports the redis client. Still it would not be best to utilise redis resources from the bull-board. Our best bet is to implement search by ID. If this is something we want to implement than I can work on a PR.

suyash-thakur avatar Jun 03 '24 18:06 suyash-thakur

Thanks @suyash-thakur That would be great if you can open such PR I think this feature will help a lot of peoples to investigate their jobs

ammirator-administrator avatar Jun 07 '24 12:06 ammirator-administrator

I recently had to implement a search by job id prefix and I believe we could use the same approach for a simple job search engine. It's still not a full search but it adds a level of flexibility in the searches. The code is pretty straightforward:

import { Queue, Job } from "bullmq";

export const getJobsByIdPrefix = async (queue: Queue, idPrefix: string, COUNT = 1000) => {
	const client = await queue.client;

	const BASE_MATCH = `bull:${queue.name}:`;
	const MATCH = `${BASE_MATCH}${idPrefix}*`;
	const [_, keys] = await client.scan(0, "MATCH", MATCH, "COUNT", COUNT);

	const promises = keys.map((key) => {
		const jobId = key.replace(BASE_MATCH, "");
		return Job.fromId(queue, jobId);
	});

	return Promise.all(promises);
}

@suyash-thakur @felixmosh What do you think about this approach?

bfbechlin avatar Aug 17 '24 20:08 bfbechlin

You are using details that related to the storage (implementation details). I don't want to know / use things that are not documented.

felixmosh avatar Aug 18 '24 04:08 felixmosh