Skip to content

Commit e873f0e

Browse files
Chris McIntoshJared Murrell
authored andcommitted
adds threadpooling for individual team syncing
1 parent a18ca46 commit e873f0e

1 file changed

Lines changed: 40 additions & 27 deletions

File tree

app.py

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import threading
88
import sys
99
import traceback
10+
from concurrent.futures import ThreadPoolExecutor
1011

1112
from apscheduler.schedulers.background import BackgroundScheduler
1213
from apscheduler.triggers.cron import CronTrigger
@@ -274,37 +275,49 @@ def sync_all_teams():
274275
Lookup teams in a GitHub org and synchronize all teams with your user directory
275276
:return:
276277
"""
278+
277279
print(f'Syncing all teams: {time.strftime("%A, %d. %B %Y %I:%M:%S %p")}')
280+
278281
installations = get_app_installations()
279282
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)
299297
)
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}")
308321

309322

310323
thread = threading.Thread(target=sync_all_teams)

0 commit comments

Comments
 (0)