Skip to content

Commit

Permalink
SQLite dbs now handle concurrent reqs better
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
Donkie committed Jun 30, 2023
1 parent 1fd8980 commit 94d8cbf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions spoolman/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,15 @@ def connect(self: "Database") -> None:
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO)

connect_args = {}
if self.connection_url.drivername == "sqlite":
connect_args["check_same_thread"] = False
elif self.connection_url.drivername == "postgresql":
connect_args["options"] = "-c timezone=utc"
connect_args["max_inactive_connection_lifetime"] = 3
if self.connection_url.drivername == "sqlite+aiosqlite":
connect_args["timeout"] = 60

self.engine = create_async_engine(
self.connection_url,
connect_args=connect_args,
pool_pre_ping=True,
)
self.session_maker = async_sessionmaker(self.engine, autocommit=False, autoflush=True)
self.session_maker = async_sessionmaker(self.engine, autocommit=False, autoflush=True, expire_on_commit=False)


__db: Optional[Database] = None
Expand Down
2 changes: 1 addition & 1 deletion tests_integration/tests/test_spool.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ async def test_use_spool_concurrent(random_filament: dict[str, Any]):
spool = result.json()

# Execute
requests = 20
requests = 100
used_weight = 0.5
async with httpx.AsyncClient() as client:
tasks = []
Expand Down

0 comments on commit 94d8cbf

Please sign in to comment.