xref: /aosp_15_r20/external/skia/infra/bots/recipe_modules/gold_upload/resources/get_uninteresting_hashes.py (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1# Copyright 2024 Google LLC
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import contextlib
7import math
8import socket
9import sys
10import time
11
12from urllib.request import urlopen
13
14HASHES_URL = sys.argv[1]
15RETRIES = 5
16TIMEOUT = 60
17WAIT_BASE = 15
18
19socket.setdefaulttimeout(TIMEOUT)
20for retry in range(RETRIES):
21  try:
22    with contextlib.closing(
23        urlopen(HASHES_URL, timeout=TIMEOUT)) as w:
24      hashes = w.read().decode('utf-8')
25      with open(sys.argv[2], 'w') as f:
26        f.write(hashes)
27        break
28  except Exception as e:
29    print('Failed to get uninteresting hashes from %s:' % HASHES_URL)
30    print(e)
31    if retry == RETRIES:
32      raise
33    waittime = WAIT_BASE * math.pow(2, retry)
34    print('Retry in %d seconds.' % waittime)
35    time.sleep(waittime)
36