Skip to content

Commit

Permalink
Merge branch 'master' into buildbot-0.8.0
Browse files Browse the repository at this point in the history
* master:
  add a default value for scheduler state 'last_processed' - fixes buildbot#816
  • Loading branch information
Dustin J. Mitchell committed May 3, 2010
2 parents 9acbdb1 + c8c0a9b commit 0ec86e4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions buildbot/changes/manager.py
Expand Up @@ -127,3 +127,5 @@ def getChangesGreaterThan(self, last_changeid, t=None):
return self.parent.db.getChangesGreaterThan(last_changeid, t)
def getChangesByNumber(self, changeids):
return self.parent.db.getChangesByNumber(changeids)
def getLatestChangeNumberNow(self, t=None):
return self.parent.db.getLatestChangeNumberNow(t)
13 changes: 13 additions & 0 deletions buildbot/db/connector.py
Expand Up @@ -369,6 +369,19 @@ def changeEventGenerator(self, branches=[], categories=[], committers=[], minTim
for (changeid,) in rows:
yield self.getChangeNumberedNow(changeid)

def getLatestChangeNumberNow(self, t=None):
if t:
return self._txn_getLatestChangeNumber(t)
else:
return self.runInteractionNow(self._txn_getLatestChangeNumber)
def _txn_getLatestChangeNumber(self, t):
q = self.quoteq("SELECT max(changeid) from changes")
t.execute(q)
row = t.fetchone()
if not row:
return 0
return row[0]

def getChangeNumberedNow(self, changeid, t=None):
# this is a synchronous/blocking version of getChangeByNumber
assert changeid >= 0
Expand Down
10 changes: 9 additions & 1 deletion buildbot/schedulers/base.py
Expand Up @@ -131,7 +131,12 @@ def classify_changes(self, t):
db = self.parent.db
cm = self.parent.change_svc
state = self.get_state(t)
last_processed = state["last_processed"]
state_changed = False
last_processed = state.get("last_processed", None)

if last_processed is None:
last_processed = state['last_processed'] = cm.getLatestChangeNumberNow(t)
state_changed = True

changes = cm.getChangesGreaterThan(last_processed, t)
for c in changes:
Expand All @@ -146,4 +151,7 @@ def classify_changes(self, t):
if changes:
max_changeid = max([c.number for c in changes])
state["last_processed"] = max_changeid # retain other keys
state_changed = True

if state_changed:
self.set_state(t, state)

0 comments on commit 0ec86e4

Please sign in to comment.