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.
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 trueYou can them perform a simple lookup to show the resizing image icon. At the end of your resque job, delete the
is_resizingkey, and add theresized_image_urlkey.