summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/docker/retry.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/tools/docker/retry.py
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/tools/docker/retry.py')
-rwxr-xr-xtesting/web-platform/tests/tools/docker/retry.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/docker/retry.py b/testing/web-platform/tests/tools/docker/retry.py
new file mode 100755
index 0000000000..8ecf5874fe
--- /dev/null
+++ b/testing/web-platform/tests/tools/docker/retry.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+import argparse
+import subprocess
+import time
+import sys
+
+
+def get_args() -> argparse.ArgumentParser:
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--delay", action="store", type=float, default=3, help="Initial delay before retry, in seconds")
+ parser.add_argument("--count", action="store", type=int, default=5, help="Total number of tries")
+ parser.add_argument("--factor", action="store", type=float, default=2, help="Exponential backoff factor")
+ parser.add_argument("cmd", nargs=argparse.REMAINDER)
+ return parser
+
+
+def log(value: str) -> None:
+ print(value)
+ sys.stdout.flush()
+
+
+def main() -> None:
+ args = get_args().parse_args()
+
+ if not args.cmd:
+ log("No command supplied")
+ sys.exit(1)
+
+ retcode = None
+
+ for n in range(args.count):
+ try:
+ log("Running %s [try %d/%d]" % (" ".join(args.cmd), (n+1), args.count))
+ subprocess.check_call(args.cmd)
+ except subprocess.CalledProcessError as e:
+ retcode = e.returncode
+ else:
+ log("Command succeeded")
+ retcode = 0
+ break
+
+ if args.factor == 0:
+ wait_time = (n+1) * args.delay
+ else:
+ wait_time = args.factor**n * args.delay
+ if n < args.count - 1:
+ log("Command failed, waiting %s seconds to retry" % wait_time)
+ time.sleep(wait_time)
+ else:
+ log("Command failed, out of retries")
+
+ sys.exit(retcode)
+
+
+if __name__ == "__main__":
+ main()