Skip to content

Commit

Permalink
[FIX] runbot: differential kill and terminate
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Jun 24, 2014
1 parent eafc1dc commit 17ba57f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions runbot/runbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def scheduler(self, cr, uid, ids=None, context=None):
# compute the number of testing job again
testing = bo.search(cr, uid, dom + [('state', '=', 'testing')], count=True)

# kill and reap doomed build
# terminate and reap doomed build
build_ids = bo.search(cr, uid, dom + [('state', '=', 'running')])
# sort builds: the last build of each sticky branch then the rest
sticky = {}
Expand All @@ -303,8 +303,8 @@ def scheduler(self, cr, uid, ids=None, context=None):
non_sticky.append(build.id)
build_ids = sticky.values()
build_ids += non_sticky
# kill extra running builds
bo.kill(cr, uid, build_ids[repo.running:])
# terminate extra running builds
bo.terminate(cr, uid, build_ids[repo.running:])
bo.reap(cr, uid, build_ids)

def nginx(self, cr, uid, context=None):
Expand Down Expand Up @@ -332,7 +332,7 @@ def killall(self, cr, uid, ids=None, context=None):
# kill switch
bo = self.pool['runbot.build']
build_ids = bo.search(cr, uid, [('state', 'not in', ['done', 'pending'])])
bo.kill(cr, uid, build_ids)
bo.terminate(cr, uid, build_ids)
bo.reap(cr, uid, build_ids)

def cron(self, cr, uid, ids=None, context=None):
Expand Down Expand Up @@ -755,22 +755,27 @@ def schedule(self, cr, uid, ids, context=None):
# needed to prevent losing pids if multiple jobs are started and one them raise an exception
cr.commit()

def kill(self, cr, uid, ids, context=None):
def terminate(self, cr, uid, ids, context=None):
for build in self.browse(cr, uid, ids, context=context):
build.logger('killing %s', build.pid)
build._log('kill', 'Kill build %s' % build.dest)
try:
os.killpg(build.pid, signal.SIGKILL)
except OSError:
pass
build.write({'state': 'done', 'result': 'killed', 'job': False})
build.github_status()
build.write({'state': 'done'})
cr.commit()
self.pg_dropdb(cr, uid, "%s-base" % build.dest)
self.pg_dropdb(cr, uid, "%s-all" % build.dest)
if os.path.isdir(build.path()):
shutil.rmtree(build.path())

def kill(self, cr, uid, ids, context=None):
for build in self.browse(cr, uid, ids, context=context):
build._log('kill', 'Kill build %s' % build.dest)
build.terminate()
build.write({'result': 'killed', 'job': False})
build.github_status()

def reap(self, cr, uid, ids):
while True:
try:
Expand Down

0 comments on commit 17ba57f

Please sign in to comment.