[banshee] DbIteratorJob: Abort job after several consecutive failures (bgo#673416)



commit 022d941fcf53067858161c7fa4cefe7f6c2d7367
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Sun May 20 18:39:53 2012 +0200

    DbIteratorJob: Abort job after several consecutive failures (bgo#673416)
    
    An exception while executing a job (in IterateCore) probably means the
    database entry will still be returned by the next execution of the
    query. This causes us to go into a tight loop of "Get entry, try to
    process it, fail".
    
    We now stop the job after 5 consecutive exceptions raised by
    IterateCore. That could mean all items have not been processed by the
    job, but it's much better than eating all the CPU...

 .../Banshee.ServiceStack/DbIteratorJob.cs          |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.ServiceStack/DbIteratorJob.cs b/src/Core/Banshee.Services/Banshee.ServiceStack/DbIteratorJob.cs
index 137cb5c..e755ea6 100644
--- a/src/Core/Banshee.Services/Banshee.ServiceStack/DbIteratorJob.cs
+++ b/src/Core/Banshee.Services/Banshee.ServiceStack/DbIteratorJob.cs
@@ -51,9 +51,13 @@ namespace Banshee.ServiceStack
 {
     public abstract class DbIteratorJob : SimpleAsyncJob
     {
+        // If we have that much consecutive errors, the job is aborted
+        private const int MAX_FAILURE_COUNT = 5;
+
         private HyenaSqliteCommand count_command;
         private HyenaSqliteCommand select_command;
         private int current_count;
+        private int failure_count;
 
         protected HyenaSqliteCommand CountCommand {
             set { count_command = value; }
@@ -106,6 +110,7 @@ namespace Banshee.ServiceStack
                 using (HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query (select_command))) {
                     if (reader.Read ()) {
                         IterateCore (reader);
+                        failure_count = 0;
                     } else {
                         return false;
                     }
@@ -115,6 +120,11 @@ namespace Banshee.ServiceStack
                 throw;
             } catch (Exception e) {
                 Log.Exception (e);
+                failure_count++;
+                if (failure_count > MAX_FAILURE_COUNT) {
+                    Log.WarningFormat ("Too many consecutive errors for job '{0}', aborting", this.Title);
+                    return false;
+                }
             } finally {
                 Progress = (double) current_count / (double) total;
                 current_count++;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]