startAutoSync method

void startAutoSync(
  1. String userId, {
  2. Duration? interval,
})

Starts automatic periodic synchronization for the specified user.

Uses interval if provided, otherwise uses DatumConfig.autoSyncInterval. Automatically stops any existing auto-sync for the same user.

Implementation

void startAutoSync(String userId, {Duration? interval}) {
  _ensureInitialized();

  if (userId.isEmpty) {
    return;
  }

  stopAutoSync(userId: userId);

  final syncInterval = interval ?? config.autoSyncInterval;

  // Schedule the first sync immediately, then schedule subsequent syncs after each completes
  _scheduleNextAutoSync(userId, syncInterval);

  _logger.info(
    'Auto-sync started for user $userId (interval: $syncInterval)',
  );
}