mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00

It's a waste to lose the entire staging if it's only a short blip / delay thing, so retry multiple times. Add utility function to make backoff functions easier (though the UI is not great ATM). Also log the "left" parent of a merge commit (which should be the "base") when creating it, for additional post-mortem information.
33 lines
972 B
Python
33 lines
972 B
Python
# -*- coding: utf-8 -*-
|
|
import itertools
|
|
import time
|
|
|
|
|
|
def shorten(text_ish, length):
|
|
""" If necessary, cuts-off the text or bytes input and appends ellipsis to
|
|
signal the cutoff, such that the result is below the provided length
|
|
(according to whatever "len" means on the text-ish so bytes or codepoints
|
|
or code units).
|
|
"""
|
|
if len(text_ish or ()) <= length:
|
|
return text_ish
|
|
|
|
cont = '...'
|
|
if isinstance(text_ish, bytes):
|
|
cont = cont.encode('ascii') # whatever
|
|
# add enough room for the ellipsis
|
|
return text_ish[:length-3] + cont
|
|
|
|
BACKOFF_DELAYS = (0.1, 0.2, 0.4, 0.8, 1.6)
|
|
def backoff(func=None, *, delays=BACKOFF_DELAYS, exc=Exception):
|
|
if func is None:
|
|
return lambda func: backoff(func, delays=delays, exc=exc)
|
|
|
|
for delay in itertools.chain(delays, [None]):
|
|
try:
|
|
return func()
|
|
except exc:
|
|
if delay is None:
|
|
raise
|
|
time.sleep(delay)
|