diff options
author | Ben Murdoch <benm@google.com> | 2010-08-11 14:44:44 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-08-12 19:15:41 +0100 |
commit | dd8bb3de4f353a81954234999f1fea748aee2ea9 (patch) | |
tree | 729b52bf09294f0d6c67cd5ea80aee1b727b7bd8 /WebKitTools/QueueStatusServer/handlers/recentstatus.py | |
parent | f3d41ba51d86bf719c7a65ab5297aea3c17e2d98 (diff) | |
download | external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.zip external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.gz external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.bz2 |
Merge WebKit at r65072 : Initial merge by git.
Change-Id: Ibcf418498376b2660aacb7f8d46ea7085ef91585
Diffstat (limited to 'WebKitTools/QueueStatusServer/handlers/recentstatus.py')
-rw-r--r-- | WebKitTools/QueueStatusServer/handlers/recentstatus.py | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/WebKitTools/QueueStatusServer/handlers/recentstatus.py b/WebKitTools/QueueStatusServer/handlers/recentstatus.py index d1df78c..e2b8c2f 100644 --- a/WebKitTools/QueueStatusServer/handlers/recentstatus.py +++ b/WebKitTools/QueueStatusServer/handlers/recentstatus.py @@ -26,32 +26,68 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import datetime + from google.appengine.ext import webapp from google.appengine.ext.webapp import template -from model.queues import queues +from model.queues import queues, display_name_for_queue from model.queuestatus import QueueStatus +from model.workitems import WorkItems + + +class QueueBubble(object): + """View support class for recentstatus.html""" + def __init__(self, queue_name): + self._queue_name = queue_name + self._work_items = WorkItems.all().filter("queue_name =", queue_name).get() + self._last_status = QueueStatus.all().filter("queue_name =", queue_name).order("-date").get() + + def name(self): + return self._queue_name + + def display_name(self): + return display_name_for_queue(self._queue_name) + + def _last_status_date(self): + if not self._last_status: + return None + return self._last_status.date + + def last_heard_from(self): + if not self._work_items: + return self._last_status_date() + return max(self._last_status_date(), self._work_items.date) + + def is_alive(self): + if not self.last_heard_from(): + return False + return self.last_heard_from() > (datetime.datetime.now() - datetime.timedelta(minutes=30)) + + def status_class(self): + if not self.is_alive(): + return "dead" + if self.pending_items_count() > 1: + return "behind" + return "alive" + + def status_text(self): + if not self._work_items: + return "Offline" + if not self._work_items.item_ids: + return "Idle" + return self._last_status.message + + def pending_items_count(self): + if not self._work_items: + return 0 + return len(self._work_items.item_ids) + -class RecentStatus(webapp.RequestHandler): - def _title_case(self, string): - words = string.split(" ") - words = map(lambda word: word.capitalize(), words) - return " ".join(words) - - def _pretty_queue_name(self, queue_name): - return self._title_case(queue_name.replace("-", " ")) - - # We could change "/" to just redirect to /queue-status/commit-queue in the future - # at which point we would not need a default value for queue_name here. - def get(self, queue_name="commit-queue"): - queue_status = {} - for queue in queues: - statuses = QueueStatus.all().filter("queue_name =", queue).order("-date").fetch(6) - if not statuses: - continue - queue_status[queue] = statuses +class QueuesOverview(webapp.RequestHandler): + def get(self): template_values = { - "queue_status" : queue_status, + "queues": [QueueBubble(queue_name) for queue_name in queues], } self.response.out.write(template.render("templates/recentstatus.html", template_values)) |