Find specific job in resque queue
Solution 1
Instead of querying resque queue, you should store image meta-data along with your model.
Lets assume you are storing product images. You are likely using a Redis hash to store product details. Just add another flag like this -
hset product:123 is_resizing true
You can them perform a simple lookup to show the resizing image icon. At the end of your resque job, delete the is_resizing
key, and add the resized_image_url
key.
Solution 2
Give resque-status a try. It is an extension to Resque that adds job tracking.
resque-status provides a set of simple classes that extend resque’s default functionality (with 0% monkey patching) to give apps a way to track specific job instances and their status. It achieves this by giving job instances UUID’s and allowing the job instances to report their status from within their iterations.
Note: d11wtq mentioned this above as a comment, but is actually the best answer so far.
Related videos on Youtube
Ronze
Updated on June 04, 2022Comments
-
Ronze almost 2 years
In my application, I'm using Resque to resize images. If an image is in the resizing queue, I want to show a "resizing image" icon.
This means that I need to be able to find all current jobs relating to a specific model ID in the queue. Right now I do it like this:
Resque.peek(:resize, 0, 100).find_all { |job| /#{model.id}/.match(job["args"][0]) }
This is stupid. But is there any way to query the Resque queue to find all jobs where the first argument is equal to [id]?
Thanks in advance.
-
d11wtq almost 12 yearsThis might interest you github.com/quirkey/resque-status
-
-
Ronze almost 12 yearsThanks for that. My app structure makes it hard to do this though, as I'm not storing any of these images in the DB. It's a requirement of my app. But I probably need some sort of table that tells me what is currently resizing. It just seems like that exact data is in the Resque que.
-
nessur about 11 yearsresque-status is genius, invaluable. Especially when you want to track the completion % of a long-running job.