2006-05-14 08:29:44 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2014-02-28 23:12:34 +00:00
|
|
|
# Copyright (C) 2006-2014 Bastian Kleineidam
|
2006-05-14 08:29:44 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
2009-07-24 21:58:20 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-05-23 22:04:30 +00:00
|
|
|
"""Status message handling"""
|
2006-05-14 08:29:44 +00:00
|
|
|
import time
|
2008-05-09 06:16:03 +00:00
|
|
|
from . import task
|
2006-05-14 08:29:44 +00:00
|
|
|
|
|
|
|
|
|
2011-12-14 21:54:26 +00:00
|
|
|
class Status (task.LoggedCheckedTask):
|
2012-11-06 20:34:22 +00:00
|
|
|
"""Thread that gathers and logs the status periodically."""
|
2006-05-14 08:29:44 +00:00
|
|
|
|
2014-03-14 20:06:10 +00:00
|
|
|
def __init__ (self, aggregator, wait_seconds):
|
2012-09-03 18:17:49 +00:00
|
|
|
"""Initialize the status logger task.
|
|
|
|
|
@param urlqueue: the URL queue
|
|
|
|
|
@ptype urlqueue: Urlqueue
|
|
|
|
|
@param logger: the logger object to inform about status
|
|
|
|
|
@ptype logger: console.StatusLogger
|
|
|
|
|
@param wait_seconds: interval in seconds to report status
|
|
|
|
|
@ptype wait_seconds: int
|
|
|
|
|
"""
|
2014-03-14 20:06:10 +00:00
|
|
|
logger = aggregator.config.status_logger
|
2011-12-14 21:54:26 +00:00
|
|
|
super(Status, self).__init__(logger)
|
2014-03-14 20:06:10 +00:00
|
|
|
self.aggregator = aggregator
|
2009-02-24 20:46:25 +00:00
|
|
|
self.wait_seconds = wait_seconds
|
2012-11-06 20:34:22 +00:00
|
|
|
assert self.wait_seconds >= 1
|
2006-05-14 08:29:44 +00:00
|
|
|
|
2006-05-24 22:16:36 +00:00
|
|
|
def run_checked (self):
|
2007-11-29 07:50:22 +00:00
|
|
|
"""Print periodic status messages."""
|
2006-05-24 22:16:36 +00:00
|
|
|
self.start_time = time.time()
|
|
|
|
|
self.setName("Status")
|
2014-02-28 23:12:34 +00:00
|
|
|
# the first status should be after a second
|
|
|
|
|
wait_seconds = 1
|
|
|
|
|
first_wait = True
|
2012-11-06 20:34:22 +00:00
|
|
|
while not self.stopped(wait_seconds):
|
2009-02-23 22:44:49 +00:00
|
|
|
self.log_status()
|
2014-02-28 23:12:34 +00:00
|
|
|
if first_wait:
|
|
|
|
|
wait_seconds = self.wait_seconds
|
|
|
|
|
first_wait = False
|
2006-05-14 08:29:44 +00:00
|
|
|
|
2009-02-23 22:44:49 +00:00
|
|
|
def log_status (self):
|
|
|
|
|
"""Log a status message."""
|
2006-05-24 22:16:36 +00:00
|
|
|
duration = time.time() - self.start_time
|
2014-03-14 20:06:10 +00:00
|
|
|
checked, in_progress, queue = self.aggregator.urlqueue.status()
|
2014-03-14 22:46:17 +00:00
|
|
|
num_urls = len(self.aggregator.result_cache)
|
|
|
|
|
self.logger.log_status(checked, in_progress, queue, duration, num_urls)
|