Files
wehub-resource-sync c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:02:24 +08:00

108 lines
3.3 KiB
Python

from uuid import UUID
from typing import List, Optional
from sqlalchemy import select, desc, and_
from cognee.modules.sync.models import SyncOperation, SyncStatus
from cognee.infrastructure.databases.relational import get_relational_engine
async def get_sync_operation(run_id: str) -> Optional[SyncOperation]:
"""
Get a sync operation by its run_id.
Args:
run_id: The public run_id of the sync operation
Returns:
SyncOperation: The sync operation record, or None if not found
"""
db_engine = get_relational_engine()
async with db_engine.get_async_session() as session:
query = select(SyncOperation).where(SyncOperation.run_id == run_id)
result = await session.execute(query)
return result.scalars().first()
async def get_user_sync_operations(
user_id: UUID, limit: int = 50, offset: int = 0
) -> List[SyncOperation]:
"""
Get sync operations for a specific user, ordered by most recent first.
Args:
user_id: UUID of the user
limit: Maximum number of records to return
offset: Number of records to skip
Returns:
List[SyncOperation]: List of sync operations for the user
"""
db_engine = get_relational_engine()
async with db_engine.get_async_session() as session:
query = (
select(SyncOperation)
.where(SyncOperation.user_id == user_id)
.order_by(desc(SyncOperation.created_at))
.limit(limit)
.offset(offset)
)
result = await session.execute(query)
return list(result.scalars().all())
async def get_sync_operations_by_dataset(
dataset_id: UUID, limit: int = 50, offset: int = 0
) -> List[SyncOperation]:
"""
Get sync operations for a specific dataset.
Args:
dataset_id: UUID of the dataset
limit: Maximum number of records to return
offset: Number of records to skip
Returns:
List[SyncOperation]: List of sync operations for the dataset
"""
db_engine = get_relational_engine()
async with db_engine.get_async_session() as session:
query = (
select(SyncOperation)
.where(SyncOperation.dataset_id == dataset_id)
.order_by(desc(SyncOperation.created_at))
.limit(limit)
.offset(offset)
)
result = await session.execute(query)
return list(result.scalars().all())
async def get_running_sync_operations_for_user(user_id: UUID) -> List[SyncOperation]:
"""
Get all currently running sync operations for a specific user.
Checks for operations with STARTED or IN_PROGRESS status.
Args:
user_id: UUID of the user
Returns:
List[SyncOperation]: List of running sync operations for the user
"""
db_engine = get_relational_engine()
async with db_engine.get_async_session() as session:
query = (
select(SyncOperation)
.where(
and_(
SyncOperation.user_id == user_id,
SyncOperation.status.in_([SyncStatus.STARTED, SyncStatus.IN_PROGRESS]),
)
)
.order_by(desc(SyncOperation.created_at))
)
result = await session.execute(query)
return list(result.scalars().all())