def check_startup_state_changed(self) -> bool:
        """Checks if PostgreSQL has completed starting up or failed or still starting.

        Should only be called when state == 'starting [after custom bootstrap]'

        :returns: True if state was changed from 'starting'
        """
        ready = self.pg_isready()

        if ready == PgIsReadyStatus.REJECT:
            return False
        elif ready == PgIsReadyStatus.NO_RESPONSE:
            ret = not self.is_running()
            if ret:
                self.set_state(PostgresqlState.START_FAILED)
                self.slots_handler.schedule(False)  # TODO: can remove this?
                self.config.save_configuration_files(True)  # TODO: maybe remove this?
            return ret
        else:
            if ready != PgIsReadyStatus.RUNNING:
                # Bad configuration or unexpected OS error. No idea of PostgreSQL status.
                # Let the main loop of run cycle clean up the mess.
                logger.warning("%s status returned from pg_isready",
                               "Unknown" if ready == PgIsReadyStatus.UNKNOWN else "Invalid")
            self.set_state(PostgresqlState.RUNNING)
            self.slots_handler.schedule()
            self.config.save_configuration_files(True)
            # TODO: __cb_pending can be None here after PostgreSQL restarts on its own. Do we want to call the callback?
            # Previously we didn't even notice.
            action = self.__cb_pending or CallbackAction.ON_START
            self.call_nowait(action)
            self.__cb_pending = None

            return True
Checks if PostgreSQL has completed starting up or failed or still starting.

        Should only be called when state == 'starting [after custom bootstrap]'

        :returns: True if state was changed from 'starting'
        
patroni/postgresql/__init__.py