def _archive_ready_wals(self) -> None:
        """Try to archive WALs that have .ready files just in case
        archive_mode was not set to 'always' before promote, while
        after it the WALs were recycled on the promoted replica.
        With this we prevent the entire loss of such WALs and the
        consequent old leader's start failure."""
        archive_mode = self._postgresql.get_guc_value('archive_mode')
        archive_cmd = self._postgresql.get_guc_value('archive_command')
        if archive_mode not in ('on', 'always') or not archive_cmd:
            return

        walseg_regex = re.compile(r'^[0-9A-F]{24}(\.partial){0,1}\.ready$')
        status_dir = os.path.join(self._postgresql.wal_dir, 'archive_status')
        try:
            wals_to_archive = [f[:-6] for f in os.listdir(status_dir) if walseg_regex.match(f)]
        except OSError as e:
            return logger.error('Unable to list %s: %r', status_dir, e)

        # skip fsync, as postgres --single or pg_rewind will anyway run it
        for wal in sorted(wals_to_archive):
            old_name = os.path.join(status_dir, wal + '.ready')
            # wal file might have already been archived
            if os.path.isfile(old_name) and os.path.isfile(os.path.join(self._postgresql.wal_dir, wal)):
                cmd = self._build_archiver_command(archive_cmd, wal)
                # it is the author of archive_command, who is responsible
                # for not overriding the WALs already present in archive
                logger.info('Trying to archive %s: %s', wal, cmd)
                if self._postgresql.cancellable.call([cmd], shell=True) == 0:
                    new_name = os.path.join(status_dir, wal + '.done')
                    try:
                        shutil.move(old_name, new_name)
                    except Exception as e:
                        logger.error('Unable to rename %s to %s: %r', old_name, new_name, e)
                else:
                    logger.info('Failed to archive WAL segment %s', wal)
Try to archive WALs that have .ready files just in case
        archive_mode was not set to 'always' before promote, while
        after it the WALs were recycled on the promoted replica.
        With this we prevent the entire loss of such WALs and the
        consequent old leader's start failure.
patroni/postgresql/rewind.py