This uses only the base-functionality with the local database.
$this->lbFactory->waitForReplication( [ 'domain' => $this->lbFactory->getLocalDomainID(), ] );
$dbr = $this->lbFactory->getMainLB()->getConnection( DB_REPLICA );
$dbw = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY );
NOTE: The pruneChanges.php maintenance script is planned to be refactored into a job in T48643: [Story] Dispatching via job queue (instead of cron script). This task here should probably done before or after that refactoring in order to avoid merge conflicts.