28
28
from feast .infra .online_stores .online_store import OnlineStore
29
29
from feast .infra .utils .postgres .connection_utils import (
30
30
_get_conn ,
31
+ _get_conn_async ,
31
32
_get_connection_pool ,
32
33
_get_connection_pool_async ,
33
34
)
@@ -57,6 +58,8 @@ class PostgreSQLOnlineStoreConfig(PostgreSQLConfig):
57
58
class PostgreSQLOnlineStore (OnlineStore ):
58
59
_conn : Optional [Connection ] = None
59
60
_conn_pool : Optional [ConnectionPool ] = None
61
+
62
+ _conn_async : Optional [AsyncConnection ] = None
60
63
_conn_pool_async : Optional [AsyncConnectionPool ] = None
61
64
62
65
@contextlib .contextmanager
@@ -79,14 +82,19 @@ def _get_conn(self, config: RepoConfig) -> Generator[Connection, Any, Any]:
79
82
async def _get_conn_async (
80
83
self , config : RepoConfig
81
84
) -> AsyncGenerator [AsyncConnection , Any ]:
82
- if not self ._conn_pool_async :
83
- self ._conn_pool_async = await _get_connection_pool_async (
84
- config .online_store
85
- )
86
- await self ._conn_pool_async .open ()
87
- connection = await self ._conn_pool_async .getconn ()
88
- yield connection
89
- await self ._conn_pool_async .putconn (connection )
85
+ if config .online_store .conn_type == ConnectionType .pool :
86
+ if not self ._conn_pool_async :
87
+ self ._conn_pool_async = await _get_connection_pool_async (
88
+ config .online_store
89
+ )
90
+ await self ._conn_pool_async .open ()
91
+ connection = await self ._conn_pool_async .getconn ()
92
+ yield connection
93
+ await self ._conn_pool_async .putconn (connection )
94
+ else :
95
+ if not self ._conn_async :
96
+ self ._conn_async = await _get_conn_async (config .online_store )
97
+ yield self ._conn_async
90
98
91
99
def online_write_batch (
92
100
self ,
0 commit comments