Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Informing the User the Status of their Query

by dru145 (Friar)
on Nov 19, 2002 at 15:45 UTC ( [id://214156]=perlquestion: print w/replies, xml ) Need Help??

dru145 has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I have a CGI program that is used to produce custom reports from our firewall logs. These reports sometimes take 30-60 min to produce. I configured Apache so the browser won't timeout while creating the report. This program also uses some system utilities to create the report so it's not all Perl based. I would like a way to let the user know the status of the report being generated. I have read Merlyn's Webtechnique article, but I'm having a hard time trying to implement this into my program. I was thinking about trying to guess how long the script will take from the users values and keep refreshing this number. Does anyone have any suggestions? Here is a summary of the action script:
#!/usr/bin/perl -w use strict; # 'taint' in the import list is currently a no-op. See the documentat +ion use CGI::Carp 'fatalsToBrowser'; use CGI::Safe qw/:standard taint/; use Mail::Sender; my $summary = param( 'summary' ) || ''; my $num_sites = param( 'websites' ) || ''; my $ip = param( 'ip' ) || ''; ... my (@days,$string,$result,$sender,$src,$direct); my $dir = "/var/tmp"; my $header = "$dir/header"; my $output = "$dir/output"; # Delete the output file if it exist unlink $output; # Run the subroutines &check_email(); &display_page(); # Delete the output file once we are done unlink $output; exit; sub check_email { # Make sure the user enters a company email address. if ($email =~ /([.\w]+)(\@acme+\.com$)/) { &do_work(); } else { die "$email is not a valid email address. Please try again.\n"; } } sub do_work { # Copy the 1st line from the log files which is necessary for fwlog +sum open (IN,"$header") or die "can't open file $header: $!"; open (OUT,">$output") or die "can't open file $output: $!"; while (<IN>) { print OUT $_; } # Add each day to an array $string = "$month1" . "$year"; @days = ($day1 .. $day2); @days = map {$_ .= "$string"} @days; # add the month and year to ea +ch day if ($summary eq 'yes') { if ($direction eq 'inbound') { ... } } elsif ($direction eq 'outbound') { .... } } elsif ($summary eq 'no') { ... } elsif ($direction eq 'outbound') { ... } close (IN); close (OUT); my $fwlogsum = "/usr/local/bin/fwlogsum -ra -w -sc -bo -T -l $outpu +t -o /exported/web-usage/$report.html"; my $fwlogsum_sum = "/usr/local/bin/fwlogsum -ra -w -sc -bo -T -S -P + $num_sites -l $output -o /exported/web-usage/$report.html"; my $fwlogsum_sum_dns = "/usr/local/bin/fwlogsum -ra -w -sc -bo -C - +T -R -S -P $num_sites -l $output -o /exported/web-usage/$report.html" +; my $fwlogsum_dns = "/usr/local/bin/fwlogsum -ra -w -sc -bo -C -T -R + -l $output -o /exported/web-usage/$report.html"; if ($dns eq 'yes' && $summary eq 'yes') { $result = `$fwlogsum_sum_dns`; } elsif ($dns eq 'yes' && $summary eq 'no'){ $result = `$fwlogsum_dns`; } elsif ($dns eq 'no' && $summary eq 'yes'){ $result = `$fwlogsum_sum`; } else { $result = `$fwlogsum`; } #end else mail(); } sub mail { ... } sub display_page { my $message = shift; print header, start_html( "-title" => "Results Page"), p(" "), p( strong("Mail Sent Ok") ), end_html; }
Thanks,
Dru
Another satisfied monk.

Replies are listed 'Best First'.
Re: Informing the User the Status of their Query
by guha (Priest) on Nov 19, 2002 at 15:58 UTC
    I would like to think that from the users perspective, at least considering a 30-60 min wait, it would be better to inform the user that processing has started and that the results could be expected by email within the next so or so minutes.
Re: Informing the User the Status of their Query
by thinker (Parson) on Nov 19, 2002 at 17:50 UTC
    Hi dru145,

    This column by our very own merlyn, Watching long processes through CGI, should help you to do what you want to do.

    cheers

    thinker

    Update: Perhaps I should make it clear that the column that I refer to is nearly five years more current than the one you were working from. It uses a different technique too, using meta refresh tags as opposed to server push. This seems to be a more universal solution.
    hope this helps
Re: Informing the User the Status of their Query
by UnderMine (Friar) on Nov 19, 2002 at 17:08 UTC
    For such long running reports I tend to use a queuing daemon. the have the webpage submit a report to the queue. This has an id. The page then refreshes at say a 1 min interval to show if the report has finished. It then shows a download link for the completed report.

    You then have a cache of previously run reports

    Hope this helps
    UnderMine

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-25 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found