Index: pending_manager.py |
diff --git a/pending_manager.py b/pending_manager.py |
index c392a91d0941dbf27d651cbd31f41f0e58e35572..621deca75824227ffae688283f9bf3e7dd2d3ec0 100644 |
--- a/pending_manager.py |
+++ b/pending_manager.py |
@@ -21,6 +21,7 @@ import ssl |
import time |
import traceback |
import urllib2 |
+import datetime |
Paweł Hajdan Jr.
2014/01/29 01:12:38
nit: Please sort imports alphabetically.
|
import find_depot_tools # pylint: disable=W0611 |
import checkout |
@@ -49,6 +50,7 @@ class PendingCommit(base.Verified): |
relpath = unicode |
# Only used after a patch was committed. Keeping here for try job retries. |
revision = (None, int, unicode) |
+ sort_key = unicode |
Paweł Hajdan Jr.
2014/01/29 01:12:38
I don't think the order of these fields is meaning
|
def __init__(self, **kwargs): |
super(PendingCommit, self).__init__(**kwargs) |
@@ -117,8 +119,8 @@ class PendingQueue(model.PersistentMixIn): |
return self.pending_commits[str(key)] |
def iterate(self): |
- """Returns the items sorted by issue id to ease testability.""" |
- return sorted(self.pending_commits.itervalues(), key=lambda x: x.issue) |
+ """Returns the items sorted by .sort_key to ease testability.""" |
+ return sorted(self.pending_commits.itervalues(), key=lambda x: x.sort_key) |
def remove(self, key): |
self.pending_commits.pop(str(key), None) |
@@ -174,6 +176,21 @@ class PendingManager(object): |
for verifier in self.pre_patch_verifiers: |
assert not isinstance(verifier, base.VerifierCheckout) |
+ @staticmethod |
Paweł Hajdan Jr.
2014/01/29 01:12:38
Looking at the body of this function it seems it s
Sergey Berezin
2014/01/29 01:54:16
Since it needs to access the 'user' option, I'm ma
|
+ def _set_sort_key(issue_data): |
+ """Compute the sorting key. Must add .sort_key to issue_data. |
+ |
+ Previously we used issue id, but a better key is the last |
+ timestamp when Commit box was checked. |
+ """ |
+ for m in issue_data['messages']: |
+ if (m['sender'] == 'commit-bot@chromium.org' |
Paweł Hajdan Jr.
2014/01/29 01:12:38
This should match the --user from commit_queue.py
|
+ and 'CQ is trying da patch.' in m['text']): |
+ issue_data['sort_key'] = m['date'] |
Paweł Hajdan Jr.
2014/01/29 01:12:38
What type is this? Sorting strings would yield dif
Sergey Berezin
2014/01/29 01:54:16
It is a string in the form 'yyyy-mm-dd hh:mm:ss.dd
|
+ if 'sort_key' not in issue_data: |
+ # Set a default value: the current time. |
+ issue_data['sort_key'] = str(datetime.datetime.utcnow()) |
+ |
def look_for_new_pending_commit(self): |
"""Looks for new reviews on self.context.rietveld with c+ set. |
@@ -206,6 +223,7 @@ class PendingManager(object): |
try: |
issue_data = self.context.rietveld.get_issue_properties( |
issue_id, True) |
+ self._set_sort_key(issue_data) |
except urllib2.HTTPError as e: |
if e.code in (500, 502, 503): |
# Temporary AppEngine hiccup. Just log it and continue. |
@@ -249,7 +267,8 @@ class PendingManager(object): |
patchset=issue_data['patchsets'][-1], |
base_url=issue_data['base_url'], |
description=issue_data['description'].replace('\r', ''), |
- messages=issue_data['messages'])) |
+ messages=issue_data['messages'], |
+ sort_key=issue_data['sort_key'])) |
def process_new_pending_commit(self): |
"""Starts verification on newly found pending commits.""" |
@@ -262,8 +281,8 @@ class PendingManager(object): |
if (not missing or pending.get_state() != base.PROCESSING): |
continue |
logging.info( |
- 'Processing issue %s (%s, %d)' % ( |
- pending.issue, missing, pending.get_state())) |
+ 'Processing issue %s @ %s (%s, %d)' % ( |
+ pending.issue, pending.sort_key, missing, pending.get_state())) |
self._verify_pending(pending) |
except base.DiscardPending as e: |
message = e.status |