[pan2: 36/68] Bug 609355: save tasks on exit



commit 6f5bff153928f19c0df59f3261b6d15165898237
Author: K. Haley <haleykd users sf net>
Date:   Sun Jun 20 15:28:53 2010 -0600

    Bug 609355: save tasks on exit
    
    Previously Pan would only save the tasks ofter a set amount of time.  This
    meant that completed tasks could still be in the file upon restart.  This
    patch fixes that problem by removing completed tasks and saving the file
    upon destruction of the queue.

 pan/tasks/queue.cc |   13 +++++++++++--
 pan/tasks/queue.h  |    1 +
 2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/pan/tasks/queue.cc b/pan/tasks/queue.cc
index d424e4e..25503c5 100644
--- a/pan/tasks/queue.cc
+++ b/pan/tasks/queue.cc
@@ -63,6 +63,8 @@ Queue :: ~Queue ()
     delete it->second;
   _pools.clear ();
 
+  clean_n_save();
+
   foreach (TaskSet, _tasks, it)
     delete *it;
 }
@@ -104,9 +106,8 @@ Queue :: get_pool (const Quark& servername)
 /***
 ****
 ***/
-
 void
-Queue :: upkeep ()
+Queue :: clean_n_save ()
 {
   const tasks_t tmp (_tasks.begin(), _tasks.end());
   // remove completed tasks.
@@ -125,6 +126,14 @@ Queue :: upkeep ()
     _needs_saving = false;
     _last_time_saved = time(0);
   }
+}
+
+void
+Queue :: upkeep ()
+{
+  clean_n_save();
+
+  const tasks_t tmp (_tasks.begin(), _tasks.end());
 
   // do upkeep on the first queued task.
   // the CPU goes crazy if we run upkeep on _all_ queued tasks,
diff --git a/pan/tasks/queue.h b/pan/tasks/queue.h
index 9c71f27..db1e13b 100644
--- a/pan/tasks/queue.h
+++ b/pan/tasks/queue.h
@@ -221,6 +221,7 @@ namespace pan
 
     private:
       TaskArchive& _archive;
+      void clean_n_save ();
 
     private:
       typedef AdaptableSet<Task*, TaskWeakOrdering> TaskSet;



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