Thanks, Joey. Most appreciated.
My requirements do not involve any file processing fortunately - I'm
simply allowing users to attach files to messages which are then sent
by email via delayed_job. I'm also restricting files sizes to a few
megabytes. But even with modest file sizes (2MB), Heroku is timing out
due to the time it is taking to upload the files to S3 via carrierwave/
fog.
So ideally I was hoping for a way of decoupling the actual upload of
files to S3 into a background job but I can't find any off-the-shelf
way of doing this.
One workaround I'm considering is to store my message object without
the files initially (though initially set the attributes so that I can
call 'valid?' on them) and then to add the files as a second step via
a background job. Something like:
@message = @community.messages.build(params[:message])
if @message.valid?
attachments = @message.remove_attachments
@message.save!
@message.delay.update_attributes!(attachments) if
attachments.present?
@message.send_emails(attachments)
else
... render view with errors
The call to .notify_recipients is also a background job but by passing
'attachments' to this job it can be independent of the other job.
> Lee
On Jan 15, 1:14 am, Joey <
j...@aghion.com> wrote:
> We ran into similar difficulties uploading and processing large images
> (>5 MB). There are actually a few Heroku limitations that might be
> impacting you:
> - The web front-end times out requests that don't start getting a
> response within 30 seconds.
> - The app process is killed if it exceeds the 500-600 MB memory
> limit. It may seem like plenty, but manipulations on some images will
> temporarily require more space. Check your log after a failure to see
> if this is your problem.
> - There's a max request size of 30 MB imposed by their web front-end
> ("413 Request Entity Too Large").
>
> Even if you do image-processing in delayed_job tasks, the memory limit
> can get you. Things to try:
> - The carrierwave_backgrounder gem did not work for us. This blog
> post describes our initial approach for delaying image-processing:
http://code.dblock.org/carrierwave-delayjob-processing-of-selected-ve...