Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > CGI "please wait" message.

Reply
Thread Tools

CGI "please wait" message.

 
 
Milo Thurston
Guest
Posts: n/a
 
      06-03-2004
Apologies for the many CGI posts.

Anyway, I am attempting to set up a script that runs blast jobs,
these take some time, so a "pease wait" message whilst they are running
followed displaying the results would be good.
There are suggestiong here:
http://www.daimi.au.dk/~mailund/css/cgi-ui-ex.html
http://tech.irt.org/articles/js172/#io_buffering
....but these are for Perl.

At present, I have something like:

def results(genome)
if genome.empty?
# display the "please select a genome to search" message
else
# show a please wait message
results = run_job(genome)
if results.empty?
# print "nothing found" message
else
# print results
end
end
end

cgi.out do
cgi.html do
cgi.body {
header +
submit_buttons +
results(genome) +
footer
}
end
end

This runs but does not (of course) display the "please wait" part.
Are there any sites similar to the above giving Ruby examples?
Thanks.

--
www.sirwilliamhope.org
 
Reply With Quote
 
 
 
 
Dan Tapp
Guest
Posts: n/a
 
      06-03-2004
Milo Thurston wrote:
> Apologies for the many CGI posts.
>
> Anyway, I am attempting to set up a script that runs blast jobs,
> these take some time, so a "pease wait" message whilst they are running
> followed displaying the results would be good.


{ Snip... }
> This runs but does not (of course) display the "please wait" part.
> Are there any sites similar to the above giving Ruby examples?
> Thanks.
>


Hi Milo,

I don't have the answer to your question, since I don't know nearly
enough about the various Ruby CGI packages.

So I'd like to build upon your question to the group with one of my own.
Maybe we'll both get what we're looking for.

Back when I worked with WebObjects (which has been a couple of years),
the kit included a special toplevel component called a WOLongResponse,
which was designed for just this type of thing.

IIRC, when instantiating a WOLongResponse, the developer passed in a
Runnable which was responsible for doing the time-consuming work.

He could also optionally pass in the name of a WOComponent which would
return a custom "please wait" page, if he wanted something prettier than
the default.

This is where my memory gets cloudy (I didn't use the page that much),
but I _think_ the developer also passed in the name of the results page
to be called when the background task was complete. That is, I don't
believe the background task was responsible for generating its own page,
since the WOLongResponse would not be able to check the status on the
Runnable that way.

The WOLongResponse would start the background task, and then return the
designated "please wait" page with an embedded meta-refresh. (The
frequency of the refresh was also settable, and defaulted to something
like five seconds.

When the background task had finished, the WOLongResponse would detect
the Runnable status and swap in the final output page on the next
refresh cycle.

Soooo, that (or something like it) seems to be what Milo's looking for.
The question is, does it exist?

- dan




--
...
... dhtapp is a cox dot net account
...

 
Reply With Quote
 
 
 
 
Milo Thurston
Guest
Posts: n/a
 
      06-03-2004
Dan Tapp <dhtapp@see_sig_line.com> wrote:
> Soooo, that (or something like it) seems to be what Milo's looking for.
> The question is, does it exist?


That's definitely the sort of thing I need.
An equivalent to Perl's CGI::Carp would be good, too. I now find myself
trying to debug this on a server where the administrator won't let me
read the apache error logs...
Anyway, hopefully something will turn up.
Thanks,
Milo.

--
www.sirwilliamhope.org
 
Reply With Quote
 
Carlos
Guest
Posts: n/a
 
      06-03-2004
[Milo Thurston <(E-Mail Removed)>, 2004-06-03 12.10 CEST]
[...]
> This runs but does not (of course) display the "please wait" part.
> Are there any sites similar to the above giving Ruby examples?
> Thanks.


I don't know about any sites. Here is an approach to display the "please
wait" message.

The problem is that cgi.<methods> create strings. When you do

cgi.out { cgi.html { cgi.body { cgi.h1 { ... } } } }

all these methods create strings and only when you have a string with the
whole homepage, it is sent to the client. So, if you want to flush the
output in the middle, you can't use these methods, but have to write the
tags manually.

#!/usr/local/bin/ruby
require "cgi"
require "thread"

cgi = CGI.new "html4"

header = "<h1>HEADER</h1>"
submit_buttons = "<p><i>here the submit buttons</i></p>"

# flush output after each print or puts:
$stdout.sync=true

# manually generate the page until the point where we want to display the
# "please wait" message:
puts cgi.header
puts
puts cgi.doctype
puts "<html><head><title>Your results</title></head><body>"
puts header
puts submit_buttons

# we will put the results of our long calculation in this variable:
results = nil

# this thread will do the calculation, and in the end, will put the results
# in the variable results:
Thread.new do
# our long calculation is only sleep
begin
sleep 5
results = "<table border=1><tr><td>result 1</td>" +
"<td>result 2</td></tr></table>"
rescue
results = "<b>BIG ERROR</b>"
end
end

# show the message...
print '<b id="PLEASEWAIT">Please wait ...'

# and wait until there is any result. Meanwhile we show nice progression
# dots...
while !results
print " ."
sleep 0.5
end
# now we have the results
puts "</b>"

# this javascript is to remove the "please wait" message.
# works in mozilla
puts '<script>n=document.getElementById("PLEASEWAIT"); ' +
'n.parentNode.removeChild(n)</script>'

puts results

puts "</body></html>"



 
Reply With Quote
 
Georgy
Guest
Posts: n/a
 
      06-05-2004
There can be two options with the "please wait" trick:
1) You show a page with the "Please wait" message, then you redirect to the final page
2) You make one page with DHTML.
I did the second trick in PHP, but the language doesn't matter here. The idea is the following:
First you output the beginning of your page and finish thi spart with e.g.

<script language="vbscript">
document.body.style.cursor="wait"
document.write "<div id=dvStatus style='color:red;font-weight:700'>Loading...<br>Please wait!<br></div>"
</script>
<script language='JavaScript'>

It may be useful to *flush* the output at this point, but all seems to work w/o flush. I don't
know if Ruby's CGI buffers its output. If so, you need to switch it off or to flush the output
explicitly. Then you do your looooooong stuff: calculate 1_000_000 digits of Pi, generate
fractal pictures, print long tables to your page, whatever. When done, you output this:

<script language="VBScript">
document.body.style.cursor="default"
dvStatus.style.display="none"
</script>

and then you can print some your final stuff and finish with </body></html>
It all requires vbscript and IE at the client's site only if you want to show a hour-glass
cursor. If you don't care about the cursor, you can remove the lines relating to it and
switch to JavaScript. Then it could work for Netscape/Opera/etc too, although you
should probably change line [dvStatus.style.display="none"] too.

HTH,
Georgy

"Milo Thurston" <(E-Mail Removed)> wrote in message news:c9mr3p$t6e$(E-Mail Removed)...
| Apologies for the many CGI posts.
|
| Anyway, I am attempting to set up a script that runs blast jobs,
| these take some time, so a "pease wait" message whilst they are running
| followed displaying the results would be good.
| There are suggestiong here:
| http://www.daimi.au.dk/~mailund/css/cgi-ui-ex.html
| http://tech.irt.org/articles/js172/#io_buffering
| ...but these are for Perl.
|
| At present, I have something like:
|
| def results(genome)
| if genome.empty?
| # display the "please select a genome to search" message
| else
| # show a please wait message
| results = run_job(genome)
| if results.empty?
| # print "nothing found" message
| else
| # print results
| end
| end
| end
|
| cgi.out do
| cgi.html do
| cgi.body {
| header +
| submit_buttons +
| results(genome) +
| footer
| }
| end
| end
|
| This runs but does not (of course) display the "please wait" part.
| Are there any sites similar to the above giving Ruby examples?
| Thanks.
|
| --
| www.sirwilliamhope.org


 
Reply With Quote
 
Georgy
Guest
Posts: n/a
 
      06-05-2004

"Georgy" <(E-Mail Removed)> wrote in message news:R0gwc.17076$(E-Mail Removed) om...
| blah blah blah
| <script language='JavaScript'>

That line with JavaScript is not needed there. It slipped from my original page. Sorry.

G-:
--
Georgy Pruss
E#Mail: 'naabbcaDaddaLryDwksvKmyw'.tr('a-zA-Z','0-9a-z.@')


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(CGI-Target)Could not connect to CGI-Proxy John Smith Java 0 05-15-2006 09:21 PM
Python-cgi or Perl-cgi script doubt praba kar Python 1 07-30-2005 08:25 AM
Python CGI - Accepting Input, Invoking Another Process, Ending CGI LarsenMTL Python 4 11-04-2004 05:59 PM
Calling cgi from cgi thru 'system' function. Different behaviour on browser v/s cmd line Shailan Perl 2 12-15-2003 04:26 PM
Re: CGI Perl "use CGI" statement fail Jürgen Exner Perl 0 07-31-2003 02:00 PM



Advertisments