async def update_all_next_scheduled_runs(self):
        """Update all next_scheduled_run values for syncs with cron schedules.

        This is useful for maintenance or after changing cron schedules.
        """
        logger.debug("Starting update of all next_scheduled_run values")
        updated_count = 0
        error_count = 0

        async with get_db_context() as db:
            # Get all active syncs with cron schedules
            stmt = select(Sync).where(
                (Sync.status == SyncStatus.ACTIVE) & (Sync.cron_schedule.is_not(None))
            )
            result = await db.execute(stmt)
            syncs = result.scalars().all()
            syncs = [schemas.SyncWithoutConnections.model_validate(sync) for sync in syncs]

            if not syncs:
                logger.debug("No syncs with cron schedules found")
                return

            logger.debug(f"Found {len(syncs)} syncs with cron schedules")
            now = datetime.now(timezone.utc)

            # Process each sync
            for sync in syncs:
                try:
                    # Get the latest job for this sync
                    latest_job = await crud.sync_job.get_latest_by_sync_id(db, sync_id=sync.id)

                    # 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)
                    )

                    # Calculate the next run time
                    cron = croniter(sync.cron_schedule, last_run_time)
                    next_run = ensure_utc(cron.get_next(datetime))

                    # If next run is in the past, calculate from now
                    if next_run < now:
                        cron = croniter(sync.cron_schedule, now)
                        next_run = ensure_utc(cron.get_next(datetime))

                    # Update the sync
                    current_user = await crud.user.get_by_email(db, email=sync.created_by_email)
                    db_sync = await crud.sync.get(
                        db, id=sync.id, current_user=current_user, with_connections=False
                    )
                    if not db_sync:
                        raise ValueError(f"Could not find sync {sync.id} in database")
                    await crud.sync.update(
                        db=db,
                        db_obj=db_sync,
                        obj_in={"next_scheduled_run": next_run},
                        current_user=current_user,
                    )
                    updated_count += 1

                    logger.debug(
                        f"Updated sync {sync.id} ({sync.name}) next_scheduled_run to "
                        f"{next_run.isoformat()}"
                    )
                except Exception as e:
                    logger.error(f"Error updating sync {sync.id}: {e}", exc_info=True)
                    error_count += 1

            logger.debug(
                f"Completed update of next_scheduled_run values: "
                f"{updated_count} updated, {error_count} errors"
            )
Update all next_scheduled_run values for syncs with cron schedules.

        This is useful for maintenance or after changing cron schedules.
        
backend/airweave/platform/scheduler.py