Francois Gouget : testbot/lib: Fix job cancellation so a rescheduling happens in short order.

Alexandre Julliard julliard at winehq.org
Fri Nov 2 15:37:54 CDT 2012


Module: tools
Branch: master
Commit: 138a6920df88a81f505449309f9ac7aa32ba44a0
URL:    http://source.winehq.org/git/tools.git/?a=commit;h=138a6920df88a81f505449309f9ac7aa32ba44a0

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Fri Nov  2 00:11:58 2012 +0100

testbot/lib: Fix job cancellation so a rescheduling happens in short order.

Previously testbot would only be noticing cancelled jobs through the
SafetyNet() function which is called every 10 minutes by default. Now
we wait a couple of seconds for the SIGTERM to be served to the child
process and then rechedule so other tasks can start.

---

 testbot/bin/Engine.pl           |   11 +++++++++++
 testbot/lib/WineTestBot/Jobs.pm |   39 ++++++++++++++-------------------------
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/testbot/bin/Engine.pl b/testbot/bin/Engine.pl
index 1cc8a9b..f9be03a 100755
--- a/testbot/bin/Engine.pl
+++ b/testbot/bin/Engine.pl
@@ -153,6 +153,17 @@ sub HandleJobCancel
     return "0$ErrMessage";
   }
 
+  # Wait a couple of seconds before rescheduling so the child processes have
+  # the time to die.
+  AddEvent("JobCancel$JobKey", 2, 0, sub {
+    $Job->UpdateStatus();
+    $ErrMessage = ScheduleJobs();
+    if (defined($ErrMessage))
+    {
+      LogMsg "Scheduling problem in HandleJobCancel: $ErrMessage\n";
+    }
+  });
+
   return "1OK";
 }
 
diff --git a/testbot/lib/WineTestBot/Jobs.pm b/testbot/lib/WineTestBot/Jobs.pm
index 74547d2..c15c7af 100644
--- a/testbot/lib/WineTestBot/Jobs.pm
+++ b/testbot/lib/WineTestBot/Jobs.pm
@@ -179,39 +179,28 @@ sub Cancel
 {
   my $self = shift;
 
-  foreach my $Step (@{$self->Steps->GetItems()})
+  my $Steps = $self->Steps;
+  $Steps->AddFilter("Status", ["queued", "running"]);
+  foreach my $Step (@{$Steps->GetItems()})
   {
-    my $Status = $Step->Status;
-    if ($Status eq "queued" || $Status eq "running")
+    my $Tasks = $Step->Tasks;
+    $Tasks->AddFilter("Status", ["queued", "running"]);
+    foreach my $Task (@{$Tasks->GetItems()})
     {
-      foreach my $Task (@{$Step->Tasks->GetItems()})
+      if ($Task->Status eq "queued")
       {
-        if ($Task->Status eq "queued")
-        {
-          $Task->Status("skipped");
-          $Task->Save();
-        }
+        $Task->Status("skipped");
+        $Task->Save();
       }
-    }
-  }
-
-  foreach my $Step (@{$self->Steps->GetItems()})
-  {
-    my $Status = $Step->Status;
-    if ($Status eq "queued" || $Status eq "running")
-    {
-      foreach my $Task (@{$Step->Tasks->GetItems()})
+      elsif (defined $Task->ChildPid)
       {
-        if ($Task->Status eq "running")
-        {
-          if (defined($Task->ChildPid))
-          {
-            kill "TERM", $Task->ChildPid;
-          }
-        }
+        # We don't unset ChildPid so Task::UpdateStatus()
+        # will add a trace in the log
+        kill("TERM", $Task->ChildPid);
       }
     }
   }
+  # Let the higher layers handle updating the overall job status
 
   return undef;
 }




More information about the wine-cvs mailing list