|
| 1 | +import asyncio |
1 | 2 | import datetime
|
2 | 3 | import shutil
|
3 | 4 | from functools import partial
|
4 | 5 | from pathlib import Path
|
5 |
| -from typing import List, Optional, Set, cast |
| 6 | +from typing import List, Optional, cast |
6 | 7 |
|
7 | 8 | import git
|
8 | 9 | from ddtrace import tracer
|
@@ -196,32 +197,31 @@ async def sync_scopes(self, only_poll_updates=False, notify_on_changes=True):
|
196 | 197 |
|
197 | 198 | fetched_source_ids = set()
|
198 | 199 | skipped_scopes = []
|
199 |
| - for scope in scopes: |
200 |
| - src_id = GitPolicyFetcher.source_id(scope.policy) |
201 |
| - |
202 |
| - # Give priority to scopes that have a unique url per shard (so we'll clone all repos asap) |
203 |
| - if src_id in fetched_source_ids: |
204 |
| - skipped_scopes.append(scope) |
205 |
| - continue |
206 |
| - |
207 |
| - try: |
208 |
| - await self.sync_scope( |
209 |
| - scope=scope, |
210 |
| - force_fetch=True, |
211 |
| - notify_on_changes=notify_on_changes, |
| 200 | + async with asyncio.TaskGroup() as g: |
| 201 | + for scope in scopes: |
| 202 | + src_id = GitPolicyFetcher.source_id(scope.policy) |
| 203 | + |
| 204 | + # Give priority to scopes that have a unique url per shard (so we'll clone all repos asap) |
| 205 | + if src_id in fetched_source_ids: |
| 206 | + skipped_scopes.append(scope) |
| 207 | + continue |
| 208 | + |
| 209 | + g.create_task( |
| 210 | + self.sync_scope( |
| 211 | + scope=scope, |
| 212 | + force_fetch=True, |
| 213 | + notify_on_changes=notify_on_changes, |
| 214 | + ) |
212 | 215 | )
|
213 |
| - except Exception as e: |
214 |
| - logger.exception(f"sync_scope failed for {scope.scope_id}") |
215 |
| - |
216 |
| - fetched_source_ids.add(src_id) |
217 |
| - |
218 |
| - for scope in skipped_scopes: |
219 |
| - # No need to refetch the same repo, just check for changes |
220 |
| - try: |
221 |
| - await self.sync_scope( |
222 |
| - scope=scope, |
223 |
| - force_fetch=False, |
224 |
| - notify_on_changes=notify_on_changes, |
| 216 | + fetched_source_ids.add(src_id) |
| 217 | + |
| 218 | + async with asyncio.TaskGroup() as g: |
| 219 | + for scope in skipped_scopes: |
| 220 | + # No need to refetch the same repo, just check for changes |
| 221 | + g.create_task( |
| 222 | + self.sync_scope( |
| 223 | + scope=scope, |
| 224 | + force_fetch=False, |
| 225 | + notify_on_changes=notify_on_changes, |
| 226 | + ) |
225 | 227 | )
|
226 |
| - except Exception as e: |
227 |
| - logger.exception(f"sync_scope failed for {scope.scope_id}") |
0 commit comments