Skip to content

Commit

Permalink
Add ability to limit the number of unclaimed build requests we query
Browse files Browse the repository at this point in the history
for, and make getOldestRequestTime only request 1.
  • Loading branch information
Chris AtLee committed Jun 1, 2010
1 parent 139e54e commit 0d17b65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
23 changes: 13 additions & 10 deletions buildbot/db/connector.py
Expand Up @@ -793,16 +793,19 @@ def _txn_get_buildername_for_brid(self, t, brid):
return r[0][0]

def get_unclaimed_buildrequests(self, buildername, old, master_name,
master_incarnation, t):
t.execute(self.quoteq("SELECT br.id"
" FROM buildrequests AS br, buildsets AS bs"
" WHERE br.buildername=? AND br.complete=0"
" AND br.buildsetid=bs.id"
" AND (br.claimed_at<?"
" OR (br.claimed_by_name=?"
" AND br.claimed_by_incarnation!=?))"
" ORDER BY br.priority DESC,bs.submitted_at ASC"),
(buildername, old, master_name, master_incarnation))
master_incarnation, t, limit=None):
q = ("SELECT br.id"
" FROM buildrequests AS br, buildsets AS bs"
" WHERE br.buildername=? AND br.complete=0"
" AND br.buildsetid=bs.id"
" AND (br.claimed_at<?"
" OR (br.claimed_by_name=?"
" AND br.claimed_by_incarnation!=?))"
" ORDER BY br.priority DESC,bs.submitted_at ASC")
if limit:
q += " LIMIT %s" % limit
t.execute(self.quoteq(q),
(buildername, old, master_name, master_incarnation))
requests = [self.getBuildRequestWithNumber(brid, t)
for (brid,) in t.fetchall()]
return requests
Expand Down
11 changes: 6 additions & 5 deletions buildbot/process/builder.py
Expand Up @@ -556,21 +556,22 @@ def _start_builds(self, assignments):
self.updateBigStatus()


def getBuildable(self):
return self.db.runInteractionNow(self._getBuildable)
def _getBuildable(self, t):
def getBuildable(self, limit=None):
return self.db.runInteractionNow(self._getBuildable, limit)
def _getBuildable(self, t, limit):
now = util.now()
old = now - self.RECLAIM_INTERVAL
return self.db.get_unclaimed_buildrequests(self.name, old,
self.master_name,
self.master_incarnation,
t)
t,
limit)

def getOldestRequestTime(self):
"""Returns the timestamp of the oldest build request for this builder.
If there are no build requests, None is returned."""
buildable = self.getBuildable()
buildable = self.getBuildable(1)
if buildable:
# TODO: this is sorted by priority first, not strictly reqtime
return buildable[0].getSubmitTime()
Expand Down

0 comments on commit 0d17b65

Please sign in to comment.