I’m using delayed job for some carrierwave tasks which can take some time.
At the moment I have created a simple job with a hook on success, it looks like this:
class VideoclipDownloadJob
def initialize(video_id)
@video_id = video_id
end
def perform
Videoclip.grab_videoclips(@video_id)
end
def success(job)
Rails.logger.info { "Videoclip downloads for video: #{@video_id} complete" }
Video.find(@video_id).update_attribute(:videoclips_downloaded, Time.now)
end
end
It works OK and I have currently implemented some AJAX polling in the browser to check when the job is complete and redirect.
However, I have two issues with this approach and would love to get some advice on this.
Firstly, if a user does not have javascript currently there is no way of redirecting them after the job is complete.
Therefore I would ideally like to include a redirect_to in the success hook in my job. I tried to add this directly into the success(job) method without success and also to create a method in my model to do it.
At that point it made me realise that it does not seem like a good MVC pattern.
Should I therefore rely purely on javascript or is there a better alternative?
My second question relates more to using Carrierwave.
It is working fine for the basic transferring of files, but the files can be quite large and I would really like to be able to not only show two states… downloading and complete, but also a progress (in percentage) of the actual transfer.
On the client side I can poll this information in the same way as I am for the jobs.
BUT – I cannot find in the Carrierwave documentation any mention of a way to find out the specific progress of an uploader.
Any advice on the best ways to achieve these two things would be very much appreciated.
Thanks,
Chris
redirect_to is a response to a browser/js request. When you have scheduled a background job and JS is disabled, you cannot redirect the user if his browser has not made any new request. And if you redirect him when his browser makes a new request, it may not be such a good idea because you may be interrupting his work.