|
7 | 7 | import threading |
8 | 8 | import sys |
9 | 9 | import traceback |
| 10 | +from concurrent.futures import ThreadPoolExecutor |
10 | 11 |
|
11 | 12 | from apscheduler.schedulers.background import BackgroundScheduler |
12 | 13 | from apscheduler.triggers.cron import CronTrigger |
@@ -274,37 +275,49 @@ def sync_all_teams(): |
274 | 275 | Lookup teams in a GitHub org and synchronize all teams with your user directory |
275 | 276 | :return: |
276 | 277 | """ |
| 278 | + |
277 | 279 | print(f'Syncing all teams: {time.strftime("%A, %d. %B %Y %I:%M:%S %p")}') |
| 280 | + |
278 | 281 | installations = get_app_installations() |
279 | 282 | custom_map = load_custom_map() |
280 | | - for i in installations(): |
281 | | - print("========================================================") |
282 | | - print(f"## Processing Organization: {i.account['login']}") |
283 | | - print("========================================================") |
284 | | - with app.app_context() as ctx: |
285 | | - try: |
286 | | - gh = GitHubApp(ctx.push()) |
287 | | - client = gh.app_installation(installation_id=i.id) |
288 | | - org = client.organization(i.account["login"]) |
289 | | - for team in org.teams(): |
290 | | - try: |
291 | | - if SYNCMAP_ONLY and team.slug not in custom_map: |
292 | | - print(f"skipping team {team.slug} - not in sync map") |
293 | | - continue |
294 | | - sync_team( |
295 | | - client=client, |
296 | | - owner=org.login, |
297 | | - team_id=team.id, |
298 | | - slug=team.slug, |
| 283 | + futures = [] |
| 284 | + with ThreadPoolExecutor(max_workers=10) as exe: |
| 285 | + for i in installations(): |
| 286 | + print("========================================================") |
| 287 | + print(f"## Processing Organization: {i.account['login']}") |
| 288 | + print("========================================================") |
| 289 | + with app.app_context() as ctx: |
| 290 | + try: |
| 291 | + gh = GitHubApp(ctx.push()) |
| 292 | + client = gh.app_installation(installation_id=i.id) |
| 293 | + org = client.organization(i.account["login"]) |
| 294 | + for team in org.teams(): |
| 295 | + futures.append( |
| 296 | + exe.submit(sync_team_helper, team, custom_map, client, org) |
299 | 297 | ) |
300 | | - except Exception as e: |
301 | | - print(f"Organization: {org.login}") |
302 | | - print(f"Unable to sync team: {team.slug}") |
303 | | - print(f"DEBUG: {e}") |
304 | | - except Exception as e: |
305 | | - print(f"DEBUG: {e}") |
306 | | - finally: |
307 | | - ctx.pop() |
| 298 | + except Exception as e: |
| 299 | + print(f"DEBUG: {e}") |
| 300 | + finally: |
| 301 | + ctx.pop() |
| 302 | + for future in futures: |
| 303 | + future.result() |
| 304 | + |
| 305 | + |
| 306 | +def sync_team_helper(team, custom_map, client, org): |
| 307 | + try: |
| 308 | + if SYNCMAP_ONLY and team.slug not in custom_map: |
| 309 | + print(f"skipping team {team.slug} - not in sync map") |
| 310 | + return |
| 311 | + sync_team( |
| 312 | + client=client, |
| 313 | + owner=org.login, |
| 314 | + team_id=team.id, |
| 315 | + slug=team.slug, |
| 316 | + ) |
| 317 | + except Exception as e: |
| 318 | + print(f"Organization: {org.login}") |
| 319 | + print(f"Unable to sync team: {team.slug}") |
| 320 | + print(f"DEBUG: {e}") |
308 | 321 |
|
309 | 322 |
|
310 | 323 | thread = threading.Thread(target=sync_all_teams) |
|
0 commit comments