Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Long Process Waits Until End to Display Results

by C_T (Scribe)
on Dec 13, 2004 at 19:14 UTC ( [id://414512]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Long Process Waits Until End to Display Results
in thread Long Process Waits Until End to Display Results

Seems kind of a Catch 22 situation. I need the caching for the reason you allude to. The process which is being buffered can take four hours to complete, so that's why I'm doing the caching and 5-second refreshing, to keep the browser from timing out.

But it's that caching that's keeping me from seeing real-time results.

You could use a solution like merlyn's by extending the key to be $session-$line and then retreiving each line individually.

Can you expand on this idea? I'm not sure how this would work. Wouldn't I lose the ability to display everything that had happend so far and only see the single line that was currently being displayed? Maybe some sample code (if you know any) would be helpful.

CT

Charles Thomas
Madison, WI
  • Comment on Re^4: Long Process Waits Until End to Display Results

Replies are listed 'Best First'.
Re^5: Long Process Waits Until End to Display Results
by traveler (Parson) on Dec 13, 2004 at 19:24 UTC
    I need the caching for the reason you allude to. The process which is being buffered can take four hours to complete, so that's why I'm doing the caching and 5-second refreshing, to keep the browser from timing out.

    I did not get that from your initial post. It might be helpful to see more of your code, particularly the part you use to processess the cache and send the info to the user.

      Hopefully this group of code snips will show you what is going on.

      The first part is where I create the fork. The second part is the lengthy process (one of them). The third part is how I display the results so far as processing is ongoing.

      It works fine, except it waits until createCommandFiles() is done before displaying the results instead of displaying the results so far.

      my $session = getSessionID(); my $cache = getCacheHandle(); $cache->set($session, [0, $buffer]); #===== Fork off a child process to do the processing if (my $pid = fork) { delete_all(); # get rid of old parameters param('session', $session); print redirect(self_url()); } elsif (defined($pid)) { close STDOUT; open (STDOUT, "-|"); #===== Make the command files $buffer .= "<strong>Creating command files...</strong><br>"; $cache->set($session, [0, $buffer]); createCommandFiles($cache); $buffer .= "<strong>Done creating command files.</strong><p>"; $cache->set($session, [1, $buffer]); } # if the pid is defined sub createCommandFiles($) { my $cache = shift or die "Must supply cache to getVersionReports()!\n"; #===== Change directory to our directory chdir($file_dir) or die "Couldn't chdir to $file_dir"; #===== Make each command file foreach my $device (@selected_devices_array) { my $command = "$mkcmdfile -t \"$device\""; system($command) and die "Could not run command $command : $!"; $buffer .= "Created command file for $device.<br>"; #===== Update the display cache $cache->set($session, [0, $buffer]); } } # end of createCommandFiles() #=================================================================== # D I S P L A Y R E S U L T S #=================================================================== sub displayPushResults($) { my $session = shift or die "Must supply session id to displayPushResults()!\n"; my $cache = undef; my $data = undef; #===== Get a cache handle $cache = getCacheHandle(); #===== Get the session info $data = $cache->get($session); #===== Check validity of session die "Could not reconnect to your session!\n" unless ($data and ref $ +data eq 'ARRAY'); #===== Write the header print "Content-type: text/html\n\n"; print "<html>\n"; print "<head>\n"; print "<title>CodePusher.cgi</title>\n"; print "<meta http-equiv=refresh content=5>\n" if (!($data->[0])); print "</head>\n"; print "<body>\n"; AantsHtml::printUWHeader(); #===== Title print "<center><h1>Results</h1></center>\n"; print "<p><p>\n"; #===== Print the results print "$data->[1]"; if (!$data->[0]) { print "<p><font color=red>Still processing... please wait!</font>< +br>"; } # if the code push is not done yet } # displayPushResults()
      CT
      Charles Thomas
      Madison, WI
        At least you need the equivalent of CGI's end_html (probably </body></html>) aat then end of displayPushResults per merlyn's example. Try that first. (Presumably you invoke displayPushResults when you get a session with a key.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://414512]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-23 22:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found