summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-03-21 15:55:14 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-03-21 15:55:14 +0000
commit88eaef356a6f1e3134d29a6e247cf1ebb8e52849 (patch)
tree50cc7d422589ec712e2671dec9f2294a3461c162
parenta91b3c276fa13cb57f5e19a4f8ae0d0678541978 (diff)
downloadlorry-controller-88eaef356a6f1e3134d29a6e247cf1ebb8e52849.tar.gz
Use last+interval instead of interval+due; other fixes
-rwxr-xr-xlorry-controller-webapp94
1 files changed, 41 insertions, 53 deletions
diff --git a/lorry-controller-webapp b/lorry-controller-webapp
index 70ee8f7..060d23e 100755
--- a/lorry-controller-webapp
+++ b/lorry-controller-webapp
@@ -77,7 +77,7 @@ class StateDB(object):
('from_trovehost', 'TEXT'),
('running_job', 'INT'),
('kill_job', 'INT'),
- ('due', 'INT'),
+ ('last_run', 'INT'),
('interval', 'INT'),
]
self.lorries_booleans = [
@@ -111,7 +111,7 @@ class StateDB(object):
'trovehost TEXT PRIMARY KEY, '
'lorry_interval INT, '
'ls_interval INT, '
- 'ls_due INT, '
+ 'ls_last_run INT, '
'prefixmap TEXT, '
'ignore TEXT '
')')
@@ -205,7 +205,7 @@ class StateDB(object):
def get_trove_info(self, trovehost):
c = self.get_cursor()
c.execute(
- 'SELECT lorry_interval, ls_interval, ls_due, '
+ 'SELECT lorry_interval, ls_interval, ls_last_run, '
'prefixmap, ignore '
'FROM troves WHERE trovehost IS ?',
(trovehost,))
@@ -216,7 +216,7 @@ class StateDB(object):
'trovehost': trovehost,
'lorry_interval': row[0],
'ls_interval': row[1],
- 'ls_due': row[2],
+ 'ls_last_run': row[2],
'prefixmap': row[3],
'ignore': row[4],
}
@@ -240,7 +240,7 @@ class StateDB(object):
c = self.get_cursor()
c.execute(
'INSERT INTO troves '
- '(trovehost, lorry_interval, ls_interval, ls_due, '
+ '(trovehost, lorry_interval, ls_interval, ls_last_run, '
'prefixmap, ignore) '
'VALUES (?, ?, ?, ?, ?, ?)',
(trovehost, lorry_interval, ls_interval, 0,
@@ -264,14 +264,15 @@ class StateDB(object):
c.execute('SELECT trovehost FROM troves')
return [row[0] for row in c.fetchall()]
- def set_trove_ls(self, trovehost, ls_due):
+ def set_trove_ls_last_run(self, trovehost, ls_last_run):
logging.debug(
- 'StateDB.set_trove_ls(%r,%r) called', trovehost, ls_due)
+ 'StateDB.set_trove_ls_last_run(%r,%r) called',
+ trovehost, ls_last_run)
assert self.in_transaction
c = self.get_cursor()
c.execute(
- 'UPDATE troves SET ls_due=? WHERE trovehost=?',
- (ls_due, trovehost))
+ 'UPDATE troves SET ls_last_run=? WHERE trovehost=?',
+ (ls_last_run, trovehost))
def make_lorry_info_from_row(self, row):
result = dict((t[0], row[i]) for i, t in enumerate(self.lorries_fields))
@@ -289,14 +290,15 @@ class StateDB(object):
def get_all_lorries_info(self):
c = self.get_cursor()
- c.execute('SELECT * FROM lorries ORDER BY due')
+ c.execute('SELECT * FROM lorries ORDER BY (last_run + interval)')
return [self.make_lorry_info_from_row(row) for row in c.fetchall()]
def get_lorries_paths(self):
c = self.get_cursor()
return [
row[0]
- for row in c.execute('SELECT path FROM lorries ORDER BY due')]
+ for row in c.execute(
+ 'SELECT path FROM lorries ORDER BY (last_run + interval)')]
def get_lorries_for_trove(self, trovehost):
c = self.get_cursor()
@@ -326,8 +328,8 @@ class StateDB(object):
c = self.get_cursor()
c.execute(
'INSERT INTO lorries '
- '(path, text, from_trovehost, due, interval, running_job, '
- 'kill_job) '
+ '(path, text, from_trovehost, last_run, interval, '
+ 'running_job, kill_job) '
'VALUES (?, ?, ?, ?, ?, ?, ?)',
(path, text, from_trovehost, 0, interval, None, 0))
else:
@@ -387,13 +389,14 @@ class StateDB(object):
'UPDATE lorries SET kill_job=? WHERE path=?',
(value, path))
- def set_due_timestamp(self, path, due):
- logging.debug('StateDB.set_due_timestamp(%r, %r) called', path, due)
+ def set_lorry_last_run(self, path, last_run):
+ logging.debug(
+ 'StateDB.set_lorry_last_run(%r, %r) called', path, last_run)
assert self.in_transaction
c = self.get_cursor()
c.execute(
- 'UPDATE lorries SET due=? WHERE path=?',
- (due, path))
+ 'UPDATE lorries SET last_run=? WHERE path=?',
+ (last_run, path))
def get_next_job_id(self):
logging.debug('StateDB.get_next_job_id called')
@@ -560,7 +563,8 @@ class StatusRenderer(object):
lorries = statedb.get_all_lorries_info()
now = time.time()
for lorry in lorries:
- lorry['due_nice'] = self.format_due_nicely(lorry['due'])
+ due = lorry['last_run'] + lorry['interval']
+ lorry['due_nice'] = self.format_due_nicely(due)
return lorries
def format_due_nicely(self, due):
@@ -596,10 +600,13 @@ class StatusRenderer(object):
troves = []
for trovehost in statedb.get_troves():
trove_info = statedb.get_trove_info(trovehost)
+
trove_info['ls_interval_nice'] = self.format_secs_nicely(
trove_info['ls_interval'])
- trove_info['ls_due_nice'] = self.format_due_nicely(
- trove_info['ls_due'])
+
+ ls_due = trove_info['ls_last_run'] + trove_info['ls_interval']
+ trove_info['ls_due_nice'] = self.format_due_nicely(ls_due)
+
troves.append(trove_info)
return troves
@@ -762,14 +769,6 @@ class ReadConfiguration(LorryControllerRoute):
path=path, text=text, from_trovehost='',
interval=interval)
- # Re-compute due timestamp if interval changed. Note that
- # this does override any manual re-ordering done by the
- # admin, but that can't be helped.
- if old_lorry_info and interval != old_lorry_info['interval']:
- due = (old_lorry_info['due'] - old_lorry_info['interval'] +
- interval)
- statedb.set_due_timestamp(path, due)
-
added_paths.add(path)
return added_paths
@@ -797,16 +796,6 @@ class ReadConfiguration(LorryControllerRoute):
return json.dumps(obj)
def add_trove(self, statedb, section):
- ls_due = None
- if section['trovehost'] in statedb.get_troves():
- trove_info = statedb.get_trove_info(section['trovehost'])
- ls_due = (
- trove_info['ls_due'] -
- trove_info['ls_interval'] +
- section['ls-interval'])
- if ls_due == trove_info['ls_due']:
- ls_due = None
-
statedb.add_trove(
trovehost=section['trovehost'],
lorry_interval=section['interval'],
@@ -814,9 +803,6 @@ class ReadConfiguration(LorryControllerRoute):
prefixmap=json.dumps(section['prefixmap']),
ignore=json.dumps(section['ignore']))
- if ls_due is not None:
- statedb.set_trove_ls(section['trovehost'], ls_due)
-
class ListQueue(LorryControllerRoute):
@@ -901,8 +887,8 @@ class GiveMeJob(LorryControllerRoute):
return { 'job_id': None }
def ready_to_run(self, lorry_info):
- return (lorry_info['running_job'] is None and
- lorry_info['due'] <= time.time())
+ due = lorry_info['last_run'] + lorry_info['interval']
+ return (lorry_info['running_job'] is None and due <= time.time())
def create_repository_in_local_trove(self, lorry_info):
# Create repository on local Trove. If it fails, assume
@@ -953,8 +939,7 @@ class JobUpdate(LorryControllerRoute):
path = statedb.find_lorry_running_job(job_id)
if exit is not None and exit != 'no':
lorry_info = statedb.get_lorry_info(path)
- next_run_due = int(time.time()) + lorry_info['interval']
- statedb.set_due_timestamp(path, next_run_due)
+ statedb.set_lorry_last_run(path, int(time.time()))
statedb.set_running_job(path, None)
statedb.set_job_exit(job_id, exit)
return statedb.get_lorry_info(path)
@@ -988,8 +973,8 @@ class MoveToTop(LorryControllerRoute):
lorry_infos = statedb.get_all_lorries_info()
if lorry_infos:
topmost = lorry_infos[0]
- due = min(0, topmost['due'] - 1)
- statedb.set_due_timestamp(path, due)
+ timestamp = min(0, topmost['last_run'] - 1)
+ statedb.set_lorry_last_run(path, timestamp)
return 'Lorry %s moved to top of run-queue' % path
@@ -1006,8 +991,9 @@ class MoveToBottom(LorryControllerRoute):
lorry_infos = statedb.get_all_lorries_info()
if lorry_infos:
bottommost = lorry_infos[-1]
- due = bottommost['due'] + 1
- statedb.set_due_timestamp(path, due)
+ timestamp = (
+ bottommost['last_run'] + bottommost['interval'] + 1)
+ statedb.set_lorry_last_run(path, timestamp)
return 'Lorry %s moved to bototm of run-queue' % path
@@ -1145,8 +1131,8 @@ class TroveRepositoryLister(object):
with statedb:
self.update_lorries_for_trove(statedb, trove_info, repo_map)
- new_due = int(time.time() + trove_info['ls_interval'])
- statedb.set_trove_ls(trove_info['trovehost'], new_due)
+ now = int(time.time())
+ statedb.set_trove_ls_last_run(trove_info['trovehost'], now)
def ls(self, trove_info):
if self.app_settings['debug-fake-trove']:
@@ -1249,10 +1235,11 @@ class ForceLsTrove(LorryControllerRoute):
def run(self, **kwargs):
logging.info('%s %s called', self.http_method, self.path)
- trovehost = bottle.request.formst.trovehost
+ trovehost = bottle.request.forms.trovehost
statedb = self.open_statedb()
lister = TroveRepositoryLister(self.app_settings)
+ trove_info = statedb.get_trove_info(trovehost)
try:
updated = lister.list_trove_into_statedb(statedb, trovehost)
except GitanoLsError as e:
@@ -1294,7 +1281,8 @@ class LsTroves(LorryControllerRoute):
if self.is_due(trove_info)]
def is_due(self, trove_info):
- return trove_info['ls_due'] <= time.time()
+ ls_due = trove_info['ls_last_run'] + trove_info['ls_interval']
+ return ls_due <= time.time()
class StaticFile(LorryControllerRoute):