def schedule(self, action: str) -> Optional[str]:
        """Schedule *action* to be executed.

        .. note::
            Must be called before executing a task.

        .. note::
            *action* can only be scheduled if there is no other action currently scheduled.

        :param action: action to be executed.

        :returns: ``None`` if *action* has been successfully scheduled, or the previously scheduled action, if any.
        """
        with self._scheduled_action_lock:
            if self._scheduled_action is not None:
                return self._scheduled_action
            self._scheduled_action = action
            self._is_cancelled = False
            self._finish_event.set()
        return None
Schedule *action* to be executed.

        .. note::
            Must be called before executing a task.

        .. note::
            *action* can only be scheduled if there is no other action currently scheduled.

        :param action: action to be executed.

        :returns: ``None`` if *action* has been successfully scheduled, or the previously scheduled action, if any.
        
patroni/async_executor.py