77 AsyncEngine ,
88 AsyncSession ,
99 async_sessionmaker ,
10- create_async_engine ,
1110 )
1211except ImportError as e :
1312 raise ImportError (
@@ -41,23 +40,21 @@ class DatabaseTaskStore(TaskStore):
4140
4241 def __init__ (
4342 self ,
44- db_url : str ,
43+ engine : AsyncEngine ,
4544 create_table : bool = True ,
4645 table_name : str = 'tasks' ,
4746 ) -> None :
4847 """Initializes the DatabaseTaskStore.
4948
5049 Args:
51- db_url: Database connection string.
50+ engine: An existing SQLAlchemy AsyncEngine to be used by Task Store
5251 create_table: If true, create tasks table on initialization.
5352 table_name: Name of the database table. Defaults to 'tasks'.
5453 """
5554 logger .debug (
56- f'Initializing DatabaseTaskStore with DB URL: { db_url } , table: { table_name } '
55+ f'Initializing DatabaseTaskStore with existing engine , table: { table_name } '
5756 )
58- self .engine = create_async_engine (
59- db_url , echo = False
60- ) # Set echo=True for SQL logging
57+ self .engine = engine
6158 self .async_session_maker = async_sessionmaker (
6259 self .engine , expire_on_commit = False
6360 )
@@ -83,13 +80,6 @@ async def initialize(self) -> None:
8380 self ._initialized = True
8481 logger .debug ('Database schema initialized.' )
8582
86- async def close (self ) -> None :
87- """Close the database connection engine."""
88- if self .engine :
89- logger .debug ('Closing database engine.' )
90- await self .engine .dispose ()
91- self ._initialized = False # Reset initialization status
92-
9383 async def _ensure_initialized (self ) -> None :
9484 """Ensure the database connection is initialized."""
9585 if not self ._initialized :
0 commit comments