def block_until_complete(jenkinsurl, jobs, maxwait=12000, interval=30, raise_on_timeout=True): """ Wait until all of the jobs in the list are complete. """ assert maxwait > 0 assert maxwait > interval assert interval > 0 obj_jenkins = Jenkins(jenkinsurl) obj_jobs = [obj_jenkins[jid] for jid in jobs] for time_left in xrange(maxwait, 0, -interval): still_running = [j for j in obj_jobs if j.is_queued_or_running()] if not still_running: return str_still_running = ", ".join('"%s"' % str(a) for a in still_running) log.warn("Waiting for jobs %s to complete. Will wait another %is" % (str_still_running, time_left)) time.sleep(interval) if raise_on_timeout: #noinspection PyUnboundLocalVariable raise TimeOut("Waited too long for these jobs to complete: %s" % str_still_running)
def __block(fn, expectation, timeout, delay=2): startTime = datetime.datetime.now() endTime = startTime + datetime.timedelta(seconds=timeout) while True: if fn() == expectation: break else: time.sleep(delay) if datetime.datetime.now() > endTime: raise TimeOut()