I am trying to generate a static archive (zip) as follows:
#### Model has following method
def generate_archive
dir = "/tmp/#{self.id}"
title = self.title.gsub(/^\s+/, '').gsub(/\s+$/, '').gsub(/\s+/,
'-')
id = self.id
host = "#{RAILS_ENV}_HOST".upcase.constantize
url = url_for :host => host, :controller => :topics, :action =>
:show, :id => id
logger.info "Generating topic (#{title}) archive '#{dir}'."
pid = fork do
`wget --page-requisites --html-extension --convert-links
--no-directories --recursive --level=1 -np --domains=#{host}
--directory-prefix=#{dir} #{url};`
`mv #{dir}/#{id}.html #{dir}/index.html;`
`zip -mj #{dir}/#{title}.zip #{dir}/*`
end
Process.detach(pid)
end
#### Controller is calling this method
@topic.generate_archive
send_file path, :type => 'application/zip'
### #### ### ### ### #### ###
- The problem is when I click/call on this method for the first time
then it does not work saying missing file. The zip file is not ready at
that point.
- If I go back and click again then it works fine and instantaneously
delivers the zip file.
- Is there anyway I can fix this? I tried putting sleep method,
however its not working either. And what is causing this problem? I
thought above method wouldn't return until background jobs are complete.
Any clues?
-
Thanks,
CS.
--
Posted via http://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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---