Mongrel + BackgrounDRb + File Column = Upload Progress Bar?

Hi there,

I’ve been digging around trying to find some information (mostly
examples)
on how one would handle a progress bar upload using BackgrounDRb and
File
Column. I did read http://backgroundrb.rubyforge.org/ and Ezra’s blog of
course, but I still have a few questions.

I made a simple upload form (as a test) that is submitted to the
“upload_song” action.

def upload_song
@song = Song.new(params[:song])
@song.member_id = session[:member_id]
@song.save
redirect_to :action => ‘edit_songs’
end

The question is, do I create the session[:job_key] within this method
like
so: ??

def upload_song
session[:job_key] = MiddleMan.new_worker(:class => :upload_worker,
:args
=> “Uploading song…”)
@song = Song.new(params[:song])
@song.member_id = session[:member_id]
@song.save
redirect_to :action => ‘edit_songs’
end

In my view, within the form parameters I have: <%=
periodically_call_remote(:url => {:action => ‘get_progress’}, :frequency
=>

  1. %> which calls the below method:

def get_progress
if request.xhr?
progress_percent =
MiddleMan.get_worker(session[:job_key]).progress
render :update do |page|
page.call(‘progressPercent’, ‘progressbar’, progress_percent)
page.redirect_to( :action => ‘done’) if progress_percent >=
100
end
else
redirect_to :action => ‘index’
end
end

def done
MiddleMan.delete_worker(session[:job_key])
redirect_to :action => ‘edit_songs’
end

Just for clarity sake, here’s my upload_worker class:

class UploadWorker < BackgrounDRb::Rails

attr_reader :progress

def do_work(args)
@progress = 0
start_working
end

def start_working
Thread.new do
while @progress < 100
sleep rand / 2
a = [1,3,5,7]
@progress += a[rand(a.length-1)]
if @progress > 100
@progress = 100
end
end
end
end

def progress
puts “Rails is fetching progress: #{@progress}”
Integer(@progress)
end
end

Are there any good tutorials out there that walk through the
implementation
of backgroundrb (specifically covering file uploads)? Am I close to
getting
this thing to work?

Thank you,
Dave H.

Hi~

On Jul 24, 2006, at 12:47 PM, Dave H. wrote:

Are there any good tutorials out there that walk through the
implementation of backgroundrb (specifically covering file
uploads)? Am I close to getting this thing to work?

Thank you,
Dave H.

Hey Dave-

I'm afraid that BackgrounDRb is not meant for file upload progress

bars. Since by the time youy could pass the file object to the worker
class it will have already been uploaded all the way. The progress
bar feature is for monitoring progress during a long running task. It
will not work for file uploads, sorry :wink: There is a file upload
progress bar setup that Rick O. and _why made for mongrel but i am
not sure of the status on it. I would search the mongrel mailing list
for upload progress and read what you find there to get this kind of
thing working.

Cheers-
-Ezra

Thanks for clearing that up Ezra. I will take a look into the mongrel
file
upload option.

-Dave

Ezra,

It just dawned on me, can I use backgroundrb for handling uploads in
general? I’ve been trying to figure out how to have mongrel accept
concurrent uploads, and that’s why I thought backgroundrb might be the
way
to go.

Thanks again,
Dave

Dave,

I think Ezra’s point was that backrounddb can’t be used for any kind
of file uploads because rails doesn’t receive the request until it
the web server sends it to rails, and that doesn’t happen until all
the request data is received. Backrounddb starts with a rails
request, so no go (if I understand correctly). I think you could use
mongrel_cluster for concurrent uploads if you need that. Someone
correct me if I’m wrong. I think each mongrel process gets tied up
during an upload, so having multiple mongrel process should allow you
to do what you want.

Tale care,
Sean

On 24-Jul-06, at 6:33 PM, Dave H. wrote:

On 7/24/06, Dave H. [email protected] wrote:
Hi there,
Are there any good tutorials out there that walk through the
bars. Since by the time youy could pass the file object to the
-Ezra
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


ALIEN8 RECORDINGS
P.O. BOX 666, STATION R
MONTREAL, QC
CANADA, H2S 3L1

http://www.alien8recordings.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs