Stable for SQLite and PostgreSQL

This commit is contained in:
Donald Zou
2025-12-02 14:27:51 +08:00
parent fa59de4a09
commit 024072688f
2 changed files with 15 additions and 16 deletions

View File

@@ -68,10 +68,10 @@ class PeerJobLogger:
db.select(
self.jobLogTable.c.JobID
).where(
db.or_(
(db.or_(
self.jobLogTable.c.Status == 'false',
self.jobLogTable.c.Status == 0
)
) if conn.dialect.name == 'sqlite' else self.jobLogTable.c.Status == 'false')
).group_by(
self.jobLogTable.c.JobID
).having(
@@ -97,4 +97,5 @@ class PeerJobLogger:
def vacuum(self):
with self.engine.begin() as conn:
if conn.dialect.name == 'sqlite':
print("[WGDashboard] SQLite Vacuuming PeerJogLogs Database")
conn.execute(db.text('VACUUM;'))

View File

@@ -192,24 +192,22 @@ class PeerJobs:
self.deleteJob(j)
def cleanJob(self, init = False):
failingJobs = self.JobLogger.getFailingJobs()
# with self.engine.begin() as conn:
# print(conn.dialect.name)
# for job in failingJobs:
# conn.execute(
# self.peerJobTable.update().values(
# {
# "ExpireDate": datetime.now()
# }
# ).where(self.peerJobTable.columns.JobID == job.get('JobID'))
# )
# self.JobLogger.deleteLogs(JobID=job.get('JobID'))
# self.JobLogger.log(job.get('JobID'), Message=f"Job is removed due to being stale.")
with self.engine.begin() as conn:
for job in failingJobs:
conn.execute(
self.peerJobTable.update().values(
{
"ExpireDate": datetime.now()
}
).where(self.peerJobTable.columns.JobID == job.get('JobID'))
)
self.JobLogger.deleteLogs(JobID=job.get('JobID'))
self.JobLogger.log(job.get('JobID'), Message=f"Job is removed due to being stale.")
with self.engine.connect() as conn:
if init and conn.dialect.name == 'sqlite':
print("[WGDashboard] SQLite Vacuuming...")
print("[WGDashboard] SQLite Vacuuming PeerJobs Database")
self.JobLogger.vacuum()
conn.execute(sqlalchemy.text('VACUUM;'))