Dave Hoefler
2006-Jul-24 19:47 UTC
[Rails] 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 Hoefler
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/9a48feda/attachment-0001.html
Ezra Zygmuntowicz
2006-Jul-24 20:26 UTC
[Rails] Mongrel + BackgrounDRb + File Column = Upload Progress Bar?
Hi~ On Jul 24, 2006, at 12:47 PM, Dave Hoefler wrote:> 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. > > <snip> > > 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 Hoefler >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 Olson 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/03749348/attachment.html
Dave Hoefler
2006-Jul-24 20:52 UTC
[Rails] Mongrel + BackgrounDRb + File Column = Upload Progress Bar?
Thanks for clearing that up Ezra. I will take a look into the mongrel file upload option. -Dave On 7/24/06, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote:> > Hi~ > On Jul 24, 2006, at 12:47 PM, Dave Hoefler wrote: > > 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. > > <snip> > > > 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 Hoefler > > > 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 Olson > 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/0306df34/attachment.html
Dave Hoefler
2006-Jul-24 22:33 UTC
[Rails] Mongrel + BackgrounDRb + File Column = Upload Progress Bar?
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 On 7/24/06, Dave Hoefler <dhoefler@gmail.com> wrote:> > Thanks for clearing that up Ezra. I will take a look into the mongrel file > upload option. > > -Dave > > On 7/24/06, Ezra Zygmuntowicz < ezmobius@gmail.com> wrote: > > > Hi~ > > On Jul 24, 2006, at 12:47 PM, Dave Hoefler wrote: > > > > 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. > > > > <snip> > > > > > > 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 Hoefler > > > > > > 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 Olson > > 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 > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060724/43df7170/attachment.html
Alien8 Recordings
2006-Jul-24 22:41 UTC
[Rails] Mongrel + BackgrounDRb + File Column = Upload Progress Bar?
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 Hoefler wrote:> 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 > > On 7/24/06, Dave Hoefler <dhoefler@gmail.com> wrote: > Thanks for clearing that up Ezra. I will take a look into the > mongrel file upload option. > > -Dave > > On 7/24/06, Ezra Zygmuntowicz < ezmobius@gmail.com> wrote: > Hi~ > > On Jul 24, 2006, at 12:47 PM, Dave Hoefler wrote: > > 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. > > <snip> > > > 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 Hoefler > > > 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 Olson 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails______________ ALIEN8 RECORDINGS P.O. BOX 666, STATION R MONTREAL, QC CANADA, H2S 3L1 http://www.alien8recordings.com