Skip to content

Commit

Permalink
fix: except all GitLab errors
Browse files Browse the repository at this point in the history
  • Loading branch information
max-wittig committed Apr 23, 2019
1 parent 4a1eeaa commit be63e72
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions gitlab_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
worker_count = multiprocessing.cpu_count() * 2


def error_wrapper(gen):
while True:
try:
yield next(gen)
except StopIteration:
return
except (GitlabGetError, GitlabHttpError):
pass


def memoize(func):
@functools.wraps(func)
def wrapper_decorator(*args, **kwargs):
Expand Down Expand Up @@ -210,11 +220,11 @@ def scan_group_projects(self, group_ids):
self.groups_scanned += 1
projects = self.gl_helper.get_group_projects(group)
with ThreadPoolExecutor(max_workers=worker_count) as executor:
for project in projects:
for project in error_wrapper(projects):
try:
project = self.gl.projects.get(project.id, simple=True)
executor.submit(self.scan, project)
except Exception:
except (GitlabGetError, GitlabHttpError):
continue

def write_metrics(self, path=Path.cwd() / "metrics.txt"):
Expand Down Expand Up @@ -244,11 +254,8 @@ def scan_projects(self, limit=None, args=None):
logger.info(f"with additional arguments {args}")

with ThreadPoolExecutor(max_workers=worker_count) as executor:
for project in projects:
try:
executor.submit(self.scan, project)
except Exception:
continue
for project in error_wrapper(projects):
executor.submit(self.scan, project)


def check_env_variables():
Expand Down

0 comments on commit be63e72

Please sign in to comment.