import psycopg

from ul_unipipeline.waiting.uni_wating import UniWaiting


class UniPostgresWaiting(UniWaiting):
    close_after_success: bool = True

    def get_connection_uri(self) -> str:
        raise NotImplementedError(f'method get_connection_uri was not specified for {type(self).__name__}')

    def try_to_connect(self) -> None:
        connection = psycopg.connect(self.get_connection_uri())

        if self.close_after_success:
            connection.close()
