# Mongrel + BackgrounDRb + File Column = Upload Progress Bar?

**URL:** <https://www.ruby-forum.com/t/mongrel-backgroundrb-file-column-upload-progress-bar/99677>\
**Category:** Rails\
**Created:** [July 24, 2006, 9:50pm UTC](https://www.ruby-forum.com/t/mongrel-backgroundrb-file-column-upload-progress-bar/99677 "2006-07-24T21:50:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [July 24, 2006, 9:50pm UTC](https://www.ruby-forum.com/t/mongrel-backgroundrb-file-column-upload-progress-bar/99677/1 "2006-07-24T21:50:18Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [July 24, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/mongrel-backgroundrb-file-column-upload-progress-bar/99677/2 "2006-07-24T22:27:24Z")

</div>

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 😉 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

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [July 24, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/mongrel-backgroundrb-file-column-upload-progress-bar/99677/3 "2006-07-24T22:54:08Z")

</div>

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

-Dave

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [July 25, 2006, 12:34am UTC](https://www.ruby-forum.com/t/mongrel-backgroundrb-file-column-upload-progress-bar/99677/4 "2006-07-25T00:34:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daveh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@daveh](https://www.ruby-forum.com/u/daveh)\
**Post date:** [July 25, 2006, 12:43am UTC](https://www.ruby-forum.com/t/mongrel-backgroundrb-file-column-upload-progress-bar/99677/5 "2006-07-25T00:43:46Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

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

[http://www.alien8recordings.com](http://www.alien8recordings.com)
