3 use Storable qw
/ retrieve /;
4 use File
::Temp qw
/ tempfile /;
6 use File
::Basename qw
/ basename /;
8 use Cwd qw
/ realpath /;
9 use File
::Spec
::Functions
;
10 use File
::NFSLock qw
/uncache/;
13 use CXGN
::Page
::FormattingHelpers qw
/ page_title_html blue_section_html /;
16 use CatalystX
::GlobalContext
qw( $c );
18 my $page = CXGN::Page->new("Generic SGN Cluster Job Waiting Page", "Lukas");
20 #extra_params added since I couldn't prevent encoding/decoding merges
21 # format: param1:value1::param2:value2::etc3:v3
22 # this adds parameters to the redirect page
24 my ($tmp_app_dir, $job_file, $redirect, $out_file_override, $extra_params)
25 = $page->get_arguments("tmp_app_dir", "job_file", "redirect", "out_file_override", "extra_params");
27 if( $out_file_override ) {
28 $out_file_override = realpath( $out_file_override );
30 print STDERR "OUTFILE: $out_file_override\n";
31 $out_file_override =~ m!/(data|export)/(prod|shared)|(/tmp)! && $out_file_override !~ /\.\./
32 or die "is someone trying to do something nasty? illegal out_file_override '$out_file_override'";
35 my ($message) = $page->get_arguments("message");
38 my $d = CXGN::Debug->new;
40 $tmp_app_dir =~ s!/!!g;
41 my $tmpdir = $page->path_to( $page->tempfiles_subdir($tmp_app_dir) );
43 $job_file = catfile($tmpdir,$job_file);
45 $d->d("Arguments: job_file = $job_file redirect = $redirect");
47 unless( -f $job_file ) {
48 $c->throw( message => "Job not found. Has it already been executed and the results retrieved?",
50 developer_message => "Job file was '$job_file'\n",
55 my $job = retrieve($job_file)
56 or die "Could not retrieve job_file $job_file";
59 display_not_finished($message);
63 # the job has finished
64 # copy the cluster temp file back into "apache space"
66 my (undef, $apache_temp) = tempfile( DIR=>$tmpdir,
67 TEMPLATE=>"alignXXXXXX",
70 $d->debug("COPY --> OUTFILE: ".$job->out_file()." Apache temp: $apache_temp");
72 my $job_out_file = $job->out_file();
74 uncache($job_out_file);
75 last if -f $job_out_file;
79 -f $job_out_file or die "job output file ($job_out_file) doesn't exist";
80 -r $job_out_file or die "job output file ($job_out_file) not readable";
81 -w $apache_temp or die "apache temp directory doesn't exist or not writable - won't copy";
83 # You may wish to provide a different output file to send back
84 # rather than STDOUT from the job. Use the out_file_override
85 # parameter if this is the case.
86 my $out_file = $out_file_override || $job->out_file();
87 system("ls /data/prod/tmp 2>&1 >/dev/null");
88 copy($out_file, $apache_temp)
89 or die "Can't copy result file '$out_file' to temp dir $!";
91 #clean up the job tempfiles
94 #also delete the job file
98 my $redirect_string = $redirect . basename( $apache_temp );
100 $page->client_redirect($redirect_string);
104 sub display_not_finished {
107 $message ||= "Job running, please wait.";
110 Content-type: text/html
112 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
115 <title>Job running</title>
116 <meta http-equiv="Refresh" content="3" />
117 <link rel="stylesheet" href="/css/sgn.css" type="text/css" />
121 body { padding-top: 80px }
128 <img src="/img/sgn_logo_animated.gif" alt="SGN logo"/>
130 <div>Please note: jobs are limited to 1 hour of run time.</div>
131 <img src="/img/progressbar1.gif" alt="In Progress..."/>
138 sub display_finished
{
141 my $title = page_title_html
("Job completed.");
151 <a href="$link"><b>View Result</b></a>
158 <br /><br /><br /><br />