[Bio] / RegSubMa / job-status.cgi Repository:
ViewVC logotype

View of /RegSubMa/job-status.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (download) (annotate) (vendor branch)
Wed Apr 4 17:08:51 2007 UTC (13 years, 2 months ago) by mkubal
Branch: MAIN, fig
CVS Tags: v_1_0_0, HEAD
Changes since 1.1: +0 -0 lines
initial checkin

    
use strict;
use FIG;
use FIG_Config;
use GenomeMeta;
use HTML;
use CGI;
use POSIX;
use Data::Dumper;
use File::Basename;

my $cgi = new CGI;


print $cgi->header;

my $job_spool_dir = $FIG_Config::fortyeight_jobs;

my $job_id = $cgi->param("job_id");

my $req = $cgi->param("req");

if ($req eq 'show_file' && $job_id && $job_id =~ /^\d+$/)
{
    my $file = $cgi->param("file");
    show_file($job_id, $file);
}
elsif ($job_id && $job_id =~ /^\d+$/)
{
    show_job($job_id);
}
else
{
    show_job_queue();
}

sub show_file
{
    my($job, $file) = @_;
    if ($file =~ m,/,)
    {
	return;
    }
    my $job_dir = "$job_spool_dir/$job";

    
    my $genome_id = &FIG::file_head("$job_dir/GENOME_ID");
    chomp $genome_id;
    my $path = "$job_dir/rp/$genome_id/$file";
    -f $path or $path = "$job_dir/rp.errors/$file";

    if (open(F, "<$path"))
    {
	print "<pre>\n";
	print <F>;
	print "</pre>\n";
	close(F);
    }
    else
    {
	print "File $file not found in job $job\n";
    }
}


sub show_job
{
    my($job) = @_;
    my $job_dir = "$job_spool_dir/$job";
    my $meta_file = "$job_dir/meta.xml";

    my $active = 'N';
    my $done = 'N';
    
    $active = 'Y' if (-f "$job_dir/ACTIVE");
    $done = 'Y' if (-f "$job_dir/DONE");
    my $genome = &FIG::file_head("$job_dir/GENOME");
    my $genome_id = &FIG::file_head("$job_dir/GENOME_ID");
    chomp $genome;
    chomp $genome_id;

    print "<title>$genome ($genome_id)</title>\n";
    print "<h1>$genome ($genome_id)</h1>\n";
    print "Directory: $job_dir/rp/$genome_id<br>\n";
    print "Active: $active<br>\n";
    print "Done: $done<br>\n";

    print "Stderr reports:\n";

    my @stderr_files = <$job_dir/rp.errors/*.stderr>;
    push(@stderr_files, <$job_dir/rp/quality.report>);

    #
    # Sort on last-mod time.
    #
    my @pairs = map { my @a = stat($_); [$_, $a[9]] } @stderr_files;
    my @stderr_files = map { $_->[0] } sort { $a->[1] <=> $b->[1] } @pairs;
    print "<ul>\n";
    for my $sf (@stderr_files)
    {
	my $b = basename($sf);
	my $url = "?req=show_file&job_id=$job&file=$b";
	my $link = "<a href='$url'>$b</a>";
	print "<li>$link\n";
    }
    print "</ul>\n";

    if (-f $meta_file)
    {
	my @tbl;
	my $meta = new GenomeMeta($genome_id, $meta_file);
	for my $key (sort $meta->get_metadata_keys())
	{
	    my $row = [$key];
	    my $val = $meta->get_metadata($key);
	    if (ref($val) eq 'ARRAY')
	    {
		push(@$row, map { flatten($_) } @$val);
	    }
	    else
	    {
		push(@$row, flatten($val));
	    }
	    push(@tbl, $row);
	}
	print &HTML::make_table(["Key", "Value"], \@tbl);

	my $log = $meta->get_log();
	@tbl = ();
#	print "<pre>\n" . Dumper($log) . "</pre>\n";
	for my $ent (@$log)
	{
	    my($type, $ltype, $ts, $ent) = @$ent;
	    next unless $type eq 'log_entry';
	    
	    my $ts = strftime('%c', localtime $ts);
	    #print Dumper($ent);

	    $ltype =~ s,.*/,,;
	    my $row = [$ts, $ltype];
	    if (ref($ent) eq 'ARRAY')
	    {
		push(@$row, map { flatten($_) } @$ent);
	    }
	    else
	    {
		push(@$row, flatten($ent));
	    }
	    push(@tbl, $row);
	}
	print  &HTML::make_table(['Timestamp', 'Type'], \@tbl);
    }	
}


sub show_job_queue
{
    opendir(D, $job_spool_dir) or  die "Cannot open job directory $job_spool_dir: $!\n";
    
    my @tbl;
    my @stats = qw(uploaded rp qc);
    my @hdr = ('Job ID', 'Genome', 'Genome ID', 'Active', 'Done', 'Upload Status', 'RP Status', 'QC Status');
    for my $job (sort { $a <=> $b } grep { /^\d+$/ and -d "$job_spool_dir/$_" } readdir(D))
    {
	my $row = [];
	my $job_dir = "$job_spool_dir/$job";

	my $job_link = $cgi->a({href => "?job_id=$job"}, $job);
	
	my $active = 'N';
	my $done = 'N';
	
	$active = 'Y' if (-f "$job_dir/ACTIVE");
	$done = 'Y' if (-f "$job_dir/DONE");
	my $genome = &FIG::file_head("$job_dir/GENOME");
	my $genome_id = &FIG::file_head("$job_dir/GENOME_ID");
	chomp $genome;
	chomp $genome_id;
	
	push(@$row, $job_link, $genome_id, $genome, $active, $done);
	
	if (-f "$job_dir/meta.xml")
	{
	    my $meta = new GenomeMeta($genome_id, "$job_dir/meta.xml");
	    for my $s (@stats)
	    {
		push(@$row, $meta->get_metadata("status.$s"));
	    }
	}
	push(@tbl, $row);
    }
    print HTML::make_table(\@hdr, \@tbl);
}

sub flatten
{
    my($l) = @_;

    if (ref($l) eq 'ARRAY')
    {
	return join("\t ", map { flatten($_) } @$l);
    }
    elsif (ref($l) eq 'ARRAY')
    {
	my $out = '{';
	$out .= join(", ", map { "$_: " . flatten($l->{$_}) } sort keys %$l) . "}";
    }
    else
    {
	return $l;
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3