Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed sync scopes to run in parallel #736

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions packages/opal-server/opal_server/scopes/service.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import asyncio
import datetime
import shutil
from functools import partial
from pathlib import Path
from typing import List, Optional, Set, cast
from typing import List, Optional, cast

import git
from ddtrace import tracer
Expand Down Expand Up @@ -196,32 +197,31 @@ async def sync_scopes(self, only_poll_updates=False, notify_on_changes=True):

fetched_source_ids = set()
skipped_scopes = []
for scope in scopes:
src_id = GitPolicyFetcher.source_id(scope.policy)

# Give priority to scopes that have a unique url per shard (so we'll clone all repos asap)
if src_id in fetched_source_ids:
skipped_scopes.append(scope)
continue

try:
await self.sync_scope(
scope=scope,
force_fetch=True,
notify_on_changes=notify_on_changes,
async with asyncio.TaskGroup() as g:
for scope in scopes:
src_id = GitPolicyFetcher.source_id(scope.policy)

# Give priority to scopes that have a unique url per shard (so we'll clone all repos asap)
if src_id in fetched_source_ids:
skipped_scopes.append(scope)
continue

g.create_task(
self.sync_scope(
scope=scope,
force_fetch=True,
notify_on_changes=notify_on_changes,
)
)
except Exception as e:
logger.exception(f"sync_scope failed for {scope.scope_id}")

fetched_source_ids.add(src_id)

for scope in skipped_scopes:
# No need to refetch the same repo, just check for changes
try:
await self.sync_scope(
scope=scope,
force_fetch=False,
notify_on_changes=notify_on_changes,
fetched_source_ids.add(src_id)

async with asyncio.TaskGroup() as g:
for scope in skipped_scopes:
# No need to refetch the same repo, just check for changes
g.create_task(
self.sync_scope(
scope=scope,
force_fetch=False,
notify_on_changes=notify_on_changes,
)
)
except Exception as e:
logger.exception(f"sync_scope failed for {scope.scope_id}")
Loading