[tools 1/2] testbot/cgi: Add an API to set the page refresh interval.

Francois Gouget fgouget at codeweavers.com
Tue Mar 29 11:00:15 CDT 2022


It can be called early, removing the need to override GeneratePage() 
just for that purpose.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/lib/ObjectModel/CGI/Page.pm     | 19 +++++++++++++++++++
 testbot/lib/WineTestBot/CGI/PageBase.pm | 15 ++++++++++++++-
 testbot/web/Activity.pl                 |  8 ++++----
 testbot/web/JobDetails.pl               | 16 ++++------------
 testbot/web/PatchesList.pl              | 10 +---------
 testbot/web/index.pl                    | 15 ++++-----------
 6 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/testbot/lib/ObjectModel/CGI/Page.pm b/testbot/lib/ObjectModel/CGI/Page.pm
index d5874129a..6197e4e38 100644
--- a/testbot/lib/ObjectModel/CGI/Page.pm
+++ b/testbot/lib/ObjectModel/CGI/Page.pm
@@ -141,6 +141,25 @@ sub escapeHTML($$)
   return $self->{CGIObj}->escapeHTML($String);
 }
 
+=pod
+=over 12
+
+=head1 C<SetRefreshInterval()>
+
+Sets the page refresh interval in seconds.
+
+This can be called at any point before GenerateHttpHeaders().
+
+=back
+=cut
+
+sub SetRefreshInterval($$)
+{
+  my ($self, $Seconds) = @_;
+
+  $self->{PageBase}->SetRefreshInterval($Seconds);
+}
+
 
 #
 # CGI parameters support
diff --git a/testbot/lib/WineTestBot/CGI/PageBase.pm b/testbot/lib/WineTestBot/CGI/PageBase.pm
index 6eba0e0eb..5ce070189 100644
--- a/testbot/lib/WineTestBot/CGI/PageBase.pm
+++ b/testbot/lib/WineTestBot/CGI/PageBase.pm
@@ -81,7 +81,8 @@ sub new($$$$@)
   my ($Page, $Request, $RequiredRole) = @_;
 
   my $self = {Request => $Request,
-              Session => undef};
+              Session => undef,
+              Refresh => undef};
   $self = bless $self, $class;
 
   if (defined($RequiredRole) && $RequiredRole ne "")
@@ -111,6 +112,13 @@ sub CreatePageBase($$$@)
   return WineTestBot::CGI::PageBase->new(@_);
 }
 
+sub SetRefreshInterval($$)
+{
+  my ($self, $Seconds) = @_;
+
+  $self->{Refresh} = $Seconds;
+}
+
 
 #
 # Session management
@@ -363,6 +371,11 @@ sub GenerateHttpHeaders($)
   # HTTP/1.0
   $Request->headers_out->add("Pragma", "no-cache");
 
+  if ($self->{Refresh})
+  {
+    $self->{Request}->headers_out->add("Refresh", $self->{Refresh});
+  }
+
   # Force char set
   $Request->content_type("text/html; charset=UTF-8");
 
diff --git a/testbot/web/Activity.pl b/testbot/web/Activity.pl
index d98f50a6c..cbe3f8721 100644
--- a/testbot/web/Activity.pl
+++ b/testbot/web/Activity.pl
@@ -56,6 +56,10 @@ sub _initialize($$$)
     # either).
     $self->SetParam("Hours", $HOURS_DEFAULT);
   }
+  if ($self->GetParam("Hours") <= $HOURS_DEFAULT)
+  {
+    $self->SetRefreshInterval(60);
+  }
 }
 
 sub GetPageTitle($$)
@@ -69,10 +73,6 @@ sub GeneratePage($)
 {
   my ($self) = @_;
 
-  if ($self->GetParam("Hours") <= $HOURS_DEFAULT)
-  {
-    $self->{Request}->headers_out->add("Refresh", "60");
-  }
   $self->SUPER::GeneratePage();
 }
 
diff --git a/testbot/web/JobDetails.pl b/testbot/web/JobDetails.pl
index 8d93957ce..5e302c098 100644
--- a/testbot/web/JobDetails.pl
+++ b/testbot/web/JobDetails.pl
@@ -57,6 +57,10 @@ sub _initialize($$$)
   $self->{JobId} = $JobId;
 
   $self->SUPER::_initialize($Request, $RequiredRole, CreateStepsTasks(undef, $self->{Job}));
+  if ($self->{Job}->Status =~ /^(?:queued|running)$/)
+  {
+    $self->SetRefreshInterval(30);
+  }
 }
 
 sub GetPageTitle($)
@@ -241,18 +245,6 @@ sub SortKeys($$$)
   return \@SortedKeys;
 }
 
-sub GeneratePage($)
-{
-  my ($self) = @_;
-
-  if ($self->{Job}->Status =~ /^(queued|running)$/)
-  {
-    $self->{Request}->headers_out->add("Refresh", "30");
-  }
-
-  $self->SUPER::GeneratePage();
-}
-
 sub InitMoreInfo($)
 {
   my ($self) = @_;
diff --git a/testbot/web/PatchesList.pl b/testbot/web/PatchesList.pl
index 6728a285f..04ca0208c 100644
--- a/testbot/web/PatchesList.pl
+++ b/testbot/web/PatchesList.pl
@@ -33,6 +33,7 @@ sub _initialize($$$)
   my ($self, $Request, $RequiredRole) = @_;
 
   $self->SUPER::_initialize($Request, $RequiredRole, CreatePatches());
+  $self->SetRefreshInterval(60);
 }
 
 sub SortKeys($$$)
@@ -65,15 +66,6 @@ sub GetActions($$)
   return [];
 }
 
-sub GeneratePage($)
-{
-  my ($self) = @_;
-
-  $self->{Request}->headers_out->add("Refresh", "60");
-
-  $self->SUPER::GeneratePage();
-}
-
 sub GenerateDataCell($$$$$)
 {
   my ($self, $CollectionBlock, $Item, $PropertyDescriptor, $DetailsPage) = @_;
diff --git a/testbot/web/index.pl b/testbot/web/index.pl
index 451258ec6..1f362fc32 100644
--- a/testbot/web/index.pl
+++ b/testbot/web/index.pl
@@ -268,6 +268,10 @@ sub _initialize($$$)
     # Replace with the default value so the cutoff can be calculated
     $self->SetParam("Days", $DAYS_DEFAULT);
   }
+  if (!$self->GetErrMessage() and $self->GetParam("Days") <= $DAYS_DEFAULT)
+  {
+    $self->SetRefreshInterval(60);
+  }
   # The action is a no-op so unset it to not need to redefine OnAction()
   $self->SetParam("Action", undef);
 }
@@ -280,17 +284,6 @@ sub OutputDot($$)
         "width='20' height='20' />";
 }
 
-sub GeneratePage($)
-{
-  my ($self) = @_;
-
-  if (!$self->GetErrMessage() and $self->GetParam("Days") <= $DAYS_DEFAULT)
-  {
-    $self->{Request}->headers_out->add("Refresh", "60");
-  }
-  $self->SUPER::GeneratePage();
-}
-
 sub GenerateBody($)
 {
   my ($self) = @_;
-- 
2.30.2




More information about the wine-devel mailing list