If I am saving a video file onto the server that is greater than 5mb. Should I create a background job for saving this file?
How should this be done? My video model has a title, description and attachment columns/fields. All fields are required.
In def create, instead of doing "if @video.save", I should do something like "if Resque.enqueue(Save, @video)"?
I am not exactly sure how this can be done, since passing an argument to Resque.enqueue() turns it into a hash. Second, with " "if Resque.enqueue(Save, @video)"", expects a true or false. However, Resque.enqueue can't return anything. Or am I wrong?
Button line is. What is the appropriate way to save a record using a background worker with resque + redis?
Ideally, I was thinking it should look something similar to:
def create
@video = Video.new(params[:video])
respond_to do |format|
if Resque.enqueue(Save)
...
end
end
module Save
@queue = :save
def self.perform
video = Video.new(params[:video])
video.save
return true
end
end
What are your thoughts?
Realising the situation again. I dont think uploaders are meant to have delayed jobs.. think about it. what happens if an upload file is queued at the 10nth position. Where does it expect to get the file from?
As quoted by another dev: "There are HTTP request handlers and just background processes. You need to handle the original upload in a http request handler and THEN you can fire up an external background process to upload it to S3 form the local disk".
Which means, it is normal to have a few HTTP request handlers running initially to handle these types of requests.
Hope this clears up a few things for users who end up coming across the same concern.