Module: tools Branch: master Commit: 58f242ec35fcf46074bca43d7ea457886729ae4b URL: https://source.winehq.org/git/tools.git/?a=commit;h=58f242ec35fcf46074bca43d...
Author: Francois Gouget fgouget@codeweavers.com Date: Mon Mar 1 16:15:45 2021 +0100
testbot/web: Limit the number of days shown on the index page.
By default only show jobs from the last 4 days to speed up generating and loading the page. The limit can of course be changed through the page to access older jobs. One can also get their own default by adding '?Days=N' at the end of the bookmarked TestBot URL.
Signed-off-by: Francois Gouget fgouget@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
testbot/lib/WineTestBot/Config.pm | 5 +++-- testbot/web/index.pl | 45 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/testbot/lib/WineTestBot/Config.pm b/testbot/lib/WineTestBot/Config.pm index 3127972..252c63c 100644 --- a/testbot/lib/WineTestBot/Config.pm +++ b/testbot/lib/WineTestBot/Config.pm @@ -37,7 +37,7 @@ use vars qw (@ISA @EXPORT @EXPORT_OK $UseSSL $LogDir $DataDir $BinDir $TagPrefix $ProjectName $PatchesMailingList $LDAPServer $LDAPBindDN $LDAPSearchBase $LDAPSearchFilter $LDAPRealNameAttribute $LDAPEMailAttribute $AgentPort $Tunnel - $TunnelDefaults $PrettyHostNames $JobPurgeDays + $TunnelDefaults $PrettyHostNames $DefaultIndexDays $JobPurgeDays $WebHostName $RegistrationQ $RegistrationARE $MuninAPIKey);
require Exporter; @@ -54,7 +54,7 @@ require Exporter; $TagPrefix $ProjectName $PatchesMailingList $LDAPServer $LDAPBindDN $LDAPSearchBase $LDAPSearchFilter $LDAPRealNameAttribute $LDAPEMailAttribute $AgentPort $Tunnel - $TunnelDefaults $PrettyHostNames $JobPurgeDays + $TunnelDefaults $PrettyHostNames $DefaultIndexDays $JobPurgeDays $WebHostName $RegistrationQ $RegistrationARE $MuninAPIKey); @EXPORT_OK = qw($DbDataSource $DbUsername $DbPassword);
@@ -149,6 +149,7 @@ $LDAPSearchFilter = undef; $LDAPRealNameAttribute = undef; $LDAPEMailAttribute = undef;
+$DefaultIndexDays = 4; $JobPurgeDays = 30;
if (!$::BuildEnv) diff --git a/testbot/web/index.pl b/testbot/web/index.pl index cc32bdb..603f295 100644 --- a/testbot/web/index.pl +++ b/testbot/web/index.pl @@ -236,8 +236,8 @@ sub GetDetailsPage($)
package StatusPage;
-use ObjectModel::CGI::Page; -our @ISA = qw(ObjectModel::CGI::Page); +use ObjectModel::CGI::FreeFormPage; +our @ISA = qw(ObjectModel::CGI::FreeFormPage);
use WineTestBot::Config; use WineTestBot::Engine::Notify; @@ -251,10 +251,31 @@ sub _initialize($$$) { my ($self, $Request, $RequiredRole) = @_;
+ $self->{Days} = $self->GetParam("Days"); + $self->Validate(); + $self->{start} = Time(); $self->SUPER::_initialize($Request, $RequiredRole); }
+sub Validate($) +{ + my ($self) = @_; + + if (!defined $self->{Days} or !$self->{Days}) + { + $self->{Days} = $DefaultIndexDays; + } + elsif ($self->{Days} !~ /^[0-9]{1,2}$/) + { + $self->{ErrField} = "Days"; + $self->{ErrMessage} = "The number of days must be between 1 and 99"; + $self->{Days} = $DefaultIndexDays; + return undef; + } + return $self->SUPER::Validate(); +} + sub OutputDot($$) { my ($self, $DotColor) = @_; @@ -328,12 +349,15 @@ sub GenerateBody($)
print "<h2><a name='jobs'></a>Jobs</h2>\n"; my $Jobs = CreateJobs(); + my $CutOff = time() - $self->{Days} * 24 * 60 * 60; + $Jobs->AddFilter("Submitted", [$CutOff], ">="); my $JobsCollectionBlock = new JobStatusBlock($Jobs, $self);
# We need to collect information about the tasks of all jobs except the # pretty rare queued jobs. But doing so one job at a time is inefficient so # do it all at once now and store the results in ...->{JobsInfo}. my $Tasks = CreateTasks(); + $Tasks->AddFilter("Started", [$CutOff], ">="); foreach my $Task (@{$Tasks->GetItems()}) { my $JobInfo = ($JobsCollectionBlock->{JobsInfo}->{$Task->JobId} ||= {}); @@ -353,6 +377,18 @@ sub GenerateBody($)
$JobsCollectionBlock->GenerateList();
+ print <<EOF; +<p></p> +<form id="Days" action='/' method='get'> + <div class='ItemProperty'><label>Show jobs for the past</label> + <div class='ItemValue'> + <input type='text' name='Days' maxlength='2' size='2' value='$self->{Days}' /> days + <input type='submit' value='Update'/> + </div> + </div> +</form> +EOF + print "<h2><a name='vms'></a>VMs</h2>\n"; my $VMsCollectionBlock = new VMStatusBlock(CreateVMs(), $self); $VMsCollectionBlock->GenerateList(); @@ -361,6 +397,11 @@ sub GenerateBody($) print "<p class='GeneralFooterText'>Generated in ", Elapsed($self->{start}), " s</p>\n"; }
+sub OnAction($$) +{ + my ($self, $Action) = @_; + return $self->Validate() ? 1 : undef; +}
package main;