quivr/backend/modules/sync/tasks.py
Stan Girard d41a0b4be4
Feat/auth-playground (#2605)
# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
2024-05-21 13:20:35 -07:00

49 lines
1.7 KiB
Python

import asyncio
from celery_config import celery
from logger import get_logger
from modules.knowledge.repository.storage import Storage
from modules.sync.repository.sync_files import SyncFiles
from modules.sync.service.sync_service import SyncService, SyncUserService
from modules.sync.utils.googleutils import GoogleSyncUtils
from modules.sync.utils.sharepointutils import AzureSyncUtils
logger = get_logger(__name__)
@celery.task(name="process_sync_active")
def process_sync_active():
loop = asyncio.get_event_loop()
loop.run_until_complete(_process_sync_active())
async def _process_sync_active():
sync_active_service = SyncService()
sync_user_service = SyncUserService()
sync_files_repo_service = SyncFiles()
storage = Storage()
google_sync_utils = GoogleSyncUtils(
sync_user_service=sync_user_service,
sync_active_service=sync_active_service,
sync_files_repo=sync_files_repo_service,
storage=storage,
)
azure_sync_utils = AzureSyncUtils(
sync_user_service=sync_user_service,
sync_active_service=sync_active_service,
sync_files_repo=sync_files_repo_service,
storage=storage,
)
active = await sync_active_service.get_syncs_active_in_interval()
for sync in active:
details_user_sync = sync_user_service.get_sync_user_by_id(sync.syncs_user_id)
if details_user_sync["provider"].lower() == "google":
await google_sync_utils.sync(sync_active_id=sync.id, user_id=sync.user_id)
elif details_user_sync["provider"].lower() == "azure":
await azure_sync_utils.sync(sync_active_id=sync.id, user_id=sync.user_id)
else:
logger.info("Provider not supported: %s", details_user_sync["provider"])