use new fast dashboard view
[buildfarm-server.git] / cgi-bin / show_status2.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7
8 use vars qw($dbhost $dbname $dbuser $dbpass $dbport);
9
10
11 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
12
13 my $query = new CGI;
14 my @members = $query->param('member');
15
16 my $dsn="dbi:Pg:dbname=$dbname";
17 $dsn .= ";host=$dbhost" if $dbhost;
18 $dsn .= ";port=$dbport" if $dbport;
19
20 my $db = DBI->connect($dsn,$dbuser,$dbpass) or die("$dsn,$dbuser,$dbpass,$!");
21
22 # there is possibly some redundancy in this query, but it makes
23 # a lot of the processing simpler.
24
25 my $statement = <<EOS;
26
27   select (now() at time zone 'GMT')::timestamp(0) - snapshot as when_ago,
28       sysname, snapshot, b.status, stage, branch,
29       operating_system, os_version, compiler, compiler_version, architecture 
30   from buildsystems s, 
31        build_status b natural join 
32        (select sysname, branch, max(snapshot) as snapshot
33         from build_status
34         group by sysname, branch
35         having max(snapshot) > now() - '30 days'::interval
36        ) m
37   where name = sysname
38         and s.status = 'approved'
39   order by case when branch = 'HEAD' then 0 else 1 end, 
40         branch desc, 
41         snapshot desc
42
43 EOS
44 ;
45
46 my $statrows=[];
47 my $sth=$db->prepare($statement);
48 $sth->execute;
49 while (my $row = $sth->fetchrow_hashref)
50 {
51     next if (@members && ! grep {$_ eq $row->{sysname} } @members);
52     push(@$statrows,$row);
53 }
54 $sth->finish;
55
56
57 $db->disconnect;
58
59 my $template = new Template({INCLUDE_PATH=>"/home/community/pgbuildfarm/templates"});
60
61 print "Content-Type: text/html\n\n";
62
63 $template->process("dyn/status.tt",{statrows=>$statrows});
64