[pan2] Bug 596683: change nzb task saving delay & add pref
- From: Charles Stephen Kerr <csk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pan2] Bug 596683: change nzb task saving delay & add pref
- Date: Tue, 29 Sep 2009 16:08:20 +0000 (UTC)
commit ecf9b1323b4b04acf13a634d4bfa78c013a84a68
Author: Charles Kerr <charles rebelbase com>
Date: Tue Sep 29 11:08:13 2009 -0500
Bug 596683: change nzb task saving delay & add pref
pan/data-impl/add-server.cc | 2 +-
pan/gui/pan.cc | 4 +++-
pan/tasks/queue.cc | 26 ++++++++++++++------------
pan/tasks/queue.h | 5 ++++-
4 files changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/pan/data-impl/add-server.cc b/pan/data-impl/add-server.cc
index c584df4..b8e3514 100644
--- a/pan/data-impl/add-server.cc
+++ b/pan/data-impl/add-server.cc
@@ -58,7 +58,7 @@ int main (int argc, char *argv[])
TaskArchive null_task_archive;
WorkerPool pool;
GIOChannelSocket::Creator _socket_creator;
- Queue queue (data, null_task_archive, &_socket_creator, pool, true);
+ Queue queue (data, null_task_archive, &_socket_creator, pool, true, 10);
queue.add_task (new TaskGroups (data, servername));
// start the event loop...
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index 7145f6e..1ca3d49 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -280,7 +280,9 @@ main (int argc, char *argv[])
// instantiate the queue...
WorkerPool worker_pool (4, true);
GIOChannelSocket::Creator socket_creator;
- Queue queue (data, data, &socket_creator, worker_pool, prefs.get_flag("work-online", true));
+ Queue queue (data, data, &socket_creator, worker_pool,
+ prefs.get_flag ("work-online", true),
+ prefs.get_int ("task-save-delay-secs", 10));
g_timeout_add (5000, queue_upkeep_timer_cb, &queue);
if (nzb || !groups.empty())
diff --git a/pan/tasks/queue.cc b/pan/tasks/queue.cc
index 069b265..d424e4e 100644
--- a/pan/tasks/queue.cc
+++ b/pan/tasks/queue.cc
@@ -35,13 +35,15 @@ Queue :: Queue (ServerInfo & server_info,
TaskArchive & archive,
Socket::Creator * socket_creator,
WorkerPool & pool,
- bool online):
+ bool online,
+ int save_delay_secs):
_server_info (server_info),
_is_online (online),
_socket_creator (socket_creator),
_worker_pool (pool),
_decoder (pool),
_decoder_task (0),
+ _save_delay_secs (save_delay_secs),
_needs_saving (false),
_last_time_saved (0),
_archive (archive)
@@ -106,14 +108,22 @@ Queue :: get_pool (const Quark& servername)
void
Queue :: upkeep ()
{
+ const tasks_t tmp (_tasks.begin(), _tasks.end());
+ // remove completed tasks.
+ foreach_const (tasks_t, tmp, it) {
+ Task * task (*it);
+ const Task::State& state (task->get_state());
+ if (state._work==Task::COMPLETED || _removing.count(task))
+ remove_task (task);
+ }
+
// maybe save the task list.
// only do it once in awhile to prevent thrashing.
- const tasks_t tmp (_tasks.begin(), _tasks.end());
const time_t now (time(0));
- if (_needs_saving && _last_time_saved<(now-10)) {
+ if (_needs_saving && _last_time_saved<(now-_save_delay_secs)) {
_archive.save_tasks (tmp);
_needs_saving = false;
- _last_time_saved = now;
+ _last_time_saved = time(0);
}
// do upkeep on the first queued task.
@@ -129,14 +139,6 @@ Queue :: upkeep ()
}
}
- // remove completed tasks.
- foreach_const (tasks_t, tmp, it) {
- Task * task (*it);
- const Task::State& state (task->get_state());
- if (state._work==Task::COMPLETED || _removing.count(task))
- remove_task (task);
- }
-
// upkeep on running tasks... this lets us pop open
// extra connections if the task can handle >1 connection
std::set<Task*> active;
diff --git a/pan/tasks/queue.h b/pan/tasks/queue.h
index dab944c..9c71f27 100644
--- a/pan/tasks/queue.h
+++ b/pan/tasks/queue.h
@@ -64,7 +64,8 @@ namespace pan
private AdaptableSet<Task*, TaskWeakOrdering>::Listener
{
public:
- Queue (ServerInfo&, TaskArchive&, Socket::Creator*, WorkerPool&, bool online);
+ Queue (ServerInfo&, TaskArchive&, Socket::Creator*, WorkerPool&,
+ bool online, int save_delay_secs);
virtual ~Queue ();
typedef std::vector<Task*> tasks_t;
@@ -212,6 +213,8 @@ namespace pan
void request_connections (const quarks_t& servers);
private:
+ /** don't save tasks.nzb more frequently than this setting */
+ int _save_delay_secs;
bool _needs_saving;
time_t _last_time_saved;
quarks_t _mids;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]