Commit 6ba00fbe authored by Rob Jennings's avatar Rob Jennings :whale:
Browse files

Limit the amount of import attempts before skipping

parent 599d9802
......@@ -4,6 +4,8 @@ import requests
import time
from pathlib import Path
COUNT_THRESHOLD = 15
class ProjectExportImport:
"""Helper class for exporting / importing a gitlab project."""
......@@ -30,6 +32,7 @@ class ProjectExportImport:
self.ci_cd_json_path = None
self.source_namespace = source_namespace
self.dest_namespace = dest_namespace
self.import_status_count = 0
@staticmethod
def get_headers(token):
......@@ -175,6 +178,9 @@ class ProjectExportImport:
proj_id = resp.json()["id"]
while not self.get_import_status(proj_id):
time.sleep(20)
self.import_status_count += 1
if self.import_status_count > COUNT_THRESHOLD:
raise Exception("Too many import status requests. Skipping import...")
print("Import complete!")
return proj_id
......@@ -186,6 +192,8 @@ class ProjectExportImport:
print("Import status is: ", resp.json()["import_status"])
if resp.json()["import_status"] in ["finished"]:
return True
if resp.json()["import_status"] == "failed":
raise Exception("Import failed. Skipping project...")
return False
def import_environments(self, proj_id):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment