mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-12-14 15:36:18 +00:00
Stable for SQLite and PostgreSQL
This commit is contained in:
@@ -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;'))
|
||||
@@ -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;'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user