Skip to content

Commit fe24794

Browse files
committed
fix: add retry limit for cloning
1 parent f41160e commit fe24794

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

config.json.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"access_modules": {
1010
"git_urls": [
1111
"https://github.com/browserstack/enigma-public-access-modules.git"
12-
]
12+
],
13+
"RETRY_LIMIT": 5
1314
},
1415
"enigmaGroup": {
1516
"MAIL_APPROVER_GROUPS": [

schema.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@
6969
"access_modules": {
7070
"description": "List of access modules attached to this tool",
7171
"type": "object",
72-
"additionalProperties": false,
72+
"additionalProperties": true,
7373
"properties": {
7474
"git_urls": {
7575
"description": "List of git URLs of access modules",
7676
"type": "array"
77+
},
78+
"RETRY_LIMIT": {
79+
"description": "Number of retries before raising cloning failure exception",
80+
"type": "integer",
81+
"minimum": 1
7782
}
7883
}
7984
},

scripts/clone_access_modules.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import json
22
import sys
33
import shutil
4-
from git import Repo
4+
from git import Repo, GitCommandError
5+
import time
56
import os
67

78
print("Starting cloning setup")
89
try:
910
f = open("./config.json", "r")
1011
config = json.load(f)
12+
RETRY_LIMIT = config["access_modules"]["RETRY_LIMIT"]
1113
urls = config["access_modules"]["git_urls"]
1214

1315
for each_access_module in os.listdir('Access/access_modules'):
@@ -33,10 +35,26 @@
3335
folder_name = url.split("/").pop()[:-4]
3436
folder_path = "./Access/access_modules/" + folder_name
3537
try:
36-
if specified_branch:
37-
Repo.clone_from(url, folder_path, branch=specified_branch)
38-
else:
39-
Repo.clone_from(url, folder_path)
38+
retry_exception = None
39+
for i in range(1, RETRY_LIMIT + 1):
40+
try:
41+
if specified_branch:
42+
Repo.clone_from(url, folder_path, branch=specified_branch)
43+
else:
44+
Repo.clone_from(url, folder_path)
45+
except (GitCommandError, Exception) as ex:
46+
print("error occurred: ", ex)
47+
print("retry:{1}/{2}".format(ex, i, RETRY_LIMIT))
48+
retry_exception = ex
49+
time.sleep(10 * i)
50+
print("retrying")
51+
else:
52+
retry_exception = None
53+
break
54+
if (retry_exception != None):
55+
print("max retry count reached")
56+
raise retry_exception
57+
4058
# move all folders, not files in the cloned repo to the access_modules
4159
# folder except the .git, .github and secrets folder
4260
for file in os.listdir(folder_path):
@@ -52,7 +70,7 @@
5270
)
5371
except:
5472
print("File is already present.")
55-
73+
5674
if(file == "requirements.txt"):
5775
current_requirements_file = folder_path + "/" + file
5876
#Read the requirements
@@ -64,12 +82,12 @@
6482

6583
# Merge the requirements
6684
merged_requirements = list(set(requirements1 + requirements2))
67-
85+
6886
#update the requirements.txt
6987
with open(requirements_file, 'w') as out_file:
7088
for requirement in sorted(merged_requirements):
7189
out_file.write(requirement)
72-
90+
7391
print("Cloning successful!")
7492
except Exception as e:
7593
print("error-->",e)
@@ -84,7 +102,7 @@
84102
except Exception as e:
85103
print(e)
86104
print("failed to remove " + folder_path + " folder.")
87-
105+
88106
except Exception as e:
89107
print("Access module cloning failed!")
90108
print(str(e))

scripts/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
validate(instance=config, schema=schema)
2626
logger.info("Schema validation passed!")
2727
except Exception as e:
28-
logger.error("Schema validation failed! Error is: " + e)
28+
logger.error("Schema validation failed! Error is: %s", e)
2929
traceback.format_exc()
3030
sys.exit(1)

0 commit comments

Comments
 (0)