One way you could do it:

  # in your model meth:
  def generate_archive
    was_success = false
    ...
    fname = "#{dir}/#{title}.zip"
    ...
    prev_fsize = 0
    10.times do     # or some reasonable(?) max num times.
      sleep 0.5
      begin fsize = File.size(fname); rescue; fsize = 0; end
      if prev_fsize > 0 and prev_fsize == fsize
        was_success = true
        break
      end
      prev_fsize = fsize
    end
    return was_success
  end

  # and in your controller meth:
    ...
    if @topic.generate_archive
      send_file path, :type => 'application/zip'
    else
      # show some err msg ...
    end
    ...

Note that the above assumes that the archiving process time (and
request volume) is short-enough from a user's wait-time perspective
(and app handle-ability).  However if that process takes too long (and/
or req volume is too high), then you'll probably not want to continue
to test/wait for archiving process to complete before responding, but
instead return/redirect to a screen where the user (either app-driven
or the user-selected) tests/waits for the archiving process to
complete.

Jeff

On Apr 13, 4:13 pm, Carlos Santana <rails-mailing-l...@andreas-s.net>
wrote:
> Any help please?
>
> Thanks,
> CS.
>
>
>
> Carlos Santana wrote:
> > - How do I know when it is complete? Ideally, I would like to send zip
> > file once the process is complete rather than giving arbitrary sleep
> > time.
> > - Is it possible to get an estimate of this?
>
> > -
> > Thanks,
> > CS.
>
> > Frederick Cheung wrote:
> >> On 12 Apr 2009, at 05:26, Carlos Santana wrote:
> >>> thought above method wouldn't return until background jobs are  
> >>> complete.
>
> >> If you want to wait for a process to complete you should be using
> >> Process.wait. Though if you're blocking on it like that what's the
> >> point of using fork ?
>
> >> Fred
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to