async def _process_sync(self, db: AsyncSession, sync: schemas.Sync) -> bool:
        """Process a sync to check if it's due and trigger it if needed.

        Returns:
            bool: True if the sync was triggered, False otherwise
        """
        if not sync.cron_schedule:
            logger.warning(f"Sync {sync.id} has no cron schedule, skipping")
            return False

        # Get the latest job for this sync
        logger.debug(f"Getting latest job for sync {sync.id}")
        latest_job = await crud.sync_job.get_latest_by_sync_id(db, sync_id=sync.id)
        db_user = await crud.user.get_by_email(db, email=sync.created_by_email)
        current_user = schemas.User.model_validate(db_user)

        if latest_job:
            logger.debug(
                f"Latest job for sync {sync.id} is {latest_job.id} with status {latest_job.status}"
            )
        else:
            logger.debug(f"No previous jobs found for sync {sync.id}")

        # Check if there's an active job running
        if latest_job and latest_job.status == SyncJobStatus.IN_PROGRESS:
            # Skip this sync as it's already running
            logger.debug(
                f"Sync {sync.id} ({sync.name}) already has job {latest_job.id} in progress."
            )
            # TODO: We must create a sync job that is autocancelled, to indicate to the user
            # that another sync job is already running.
            return False

        # Get the last run time (or use epoch if never run)
        last_run_time = (
            ensure_utc(latest_job.created_at)
            if latest_job
            else datetime.fromtimestamp(0, tz=timezone.utc)
        )
        logger.debug(f"Last run time for sync {sync.id}: {last_run_time.isoformat()}")

        # Calculate the next run time
        now = datetime.now(timezone.utc)
        cron = croniter(sync.cron_schedule, last_run_time)
        next_run = ensure_utc(cron.get_next(datetime))
        logger.debug(
            f"Calculated next run for sync {sync.id} at {next_run.isoformat()} "
            f"(cron: {sync.cron_schedule})"
        )

        # If next_scheduled_run is None or different from what we calculated, update it
        if (
            sync.next_scheduled_run is None
            or abs((ensure_utc(sync.next_scheduled_run) - next_run).total_seconds()) > 1
        ):
            logger.debug(
                f"Updating next_scheduled_run for sync {sync.id} from "
                f"{sync.next_scheduled_run.isoformat() if sync.next_scheduled_run else 'None'} "
                f"to {next_run.isoformat()}"
            )

            async with get_db_context() as db:
                # Get the actual SQLAlchemy model object from the database
                db_sync = await crud.sync.get(
                    db, id=sync.id, current_user=current_user, with_connections=False
                )
                if not db_sync:
                    logger.error(f"Could not find sync {sync.id} in database, skipping update")
                    return False

                # Update the next_scheduled_run field
                await crud.sync.update(
                    db=db,
                    db_obj=db_sync,
                    obj_in={"next_scheduled_run": next_run},
                    current_user=current_user,
                )
                logger.debug(f"Successfully updated next_scheduled_run for sync {sync.id}")
                # Update our local copy
                sync.next_scheduled_run = next_run

        # Check if the sync is due
        if next_run <= now:
            time_diff = (now - next_run).total_seconds()
            logger.debug(
                f"Sync {sync.id} ({sync.name}) is due (overdue by {time_diff:.1f}s), triggering"
            )
            sync_schema = await crud.sync.get(
                db, id=sync.id, current_user=current_user, with_connections=True
            )
            await self._trigger_sync(db, sync_schema)

            return True
        else:
            time_to_next = (next_run - now).total_seconds()
            logger.debug(
                f"Sync {sync.id} ({sync.name}) not due yet, next run in {time_to_next:.1f}s "
                f"at {next_run.isoformat()}"
            )
            return False
Process a sync to check if it's due and trigger it if needed.

        Returns:
            bool: True if the sync was triggered, False otherwise
        
backend/airweave/platform/scheduler.py