mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-11-16 18:36:19 +00:00
Fixed stale job issue
This commit is contained in:
@@ -173,9 +173,7 @@ class AmneziaWireguardConfiguration(WireguardConfiguration):
|
||||
self.metadata.create_all(self.engine)
|
||||
|
||||
def getPeers(self):
|
||||
self.Peers.clear()
|
||||
current_app.logger.info(f"Refreshing {self.Name} peer list")
|
||||
|
||||
self.Peers.clear()
|
||||
if self.configurationFileChanged():
|
||||
with open(self.configPath, 'r') as configFile:
|
||||
p = []
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
Peer Job Logger
|
||||
"""
|
||||
import uuid
|
||||
from typing import Sequence
|
||||
|
||||
import sqlalchemy as db
|
||||
from flask import current_app
|
||||
from sqlalchemy import RowMapping
|
||||
|
||||
from .ConnectionString import ConnectionString
|
||||
from .Log import Log
|
||||
|
||||
@@ -56,4 +60,21 @@ class PeerJobLogger:
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Getting Peer Job Log Error", e)
|
||||
return logs
|
||||
return logs
|
||||
return logs
|
||||
|
||||
def getFailingJobs(self) -> Sequence[RowMapping]:
|
||||
with self.engine.connect() as conn:
|
||||
table = conn.execute(
|
||||
db.select(
|
||||
self.jobLogTable.c.JobID
|
||||
).where(
|
||||
self.jobLogTable.c.Status == 'false'
|
||||
).group_by(
|
||||
self.jobLogTable.c.JobID
|
||||
).having(
|
||||
db.func.count(
|
||||
self.jobLogTable.c.JobID
|
||||
) > 10
|
||||
)
|
||||
).mappings().fetchall()
|
||||
return table
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Peer Jobs
|
||||
"""
|
||||
import sqlalchemy
|
||||
|
||||
from .ConnectionString import ConnectionString
|
||||
from .PeerJob import PeerJob
|
||||
from .PeerJobLogger import PeerJobLogger
|
||||
@@ -117,7 +119,7 @@ class PeerJobs:
|
||||
}
|
||||
).where(self.peerJobTable.columns.JobID == Job.JobID)
|
||||
)
|
||||
self.JobLogger.log(Job.JobID, Message=f"Job is removed due to being deleted or finshed.")
|
||||
self.JobLogger.log(Job.JobID, Message=f"Job is removed due to being deleted or finished.")
|
||||
self.__getJobs()
|
||||
self.WireguardConfigurations.get(Job.Configuration).searchPeer(Job.Peer)[1].getJobs()
|
||||
return True, None
|
||||
@@ -142,7 +144,7 @@ class PeerJobs:
|
||||
|
||||
|
||||
def runJob(self):
|
||||
current_app.logger.info("Running scheduled jobs")
|
||||
self.cleanJob()
|
||||
needToDelete = []
|
||||
self.__getJobs()
|
||||
for job in self.Jobs:
|
||||
@@ -172,10 +174,8 @@ class PeerJobs:
|
||||
self.JobLogger.log(job.JobID, s,
|
||||
f"Peer {fp.id} from {c.Name} is successfully {job.Action}ed."
|
||||
)
|
||||
current_app.logger.info(f"Peer {fp.id} from {c.Name} is successfully {job.Action}ed.")
|
||||
needToDelete.append(job)
|
||||
else:
|
||||
current_app.logger.info(f"Peer {fp.id} from {c.Name} is failed {job.Action}ed.")
|
||||
self.JobLogger.log(job.JobID, s,
|
||||
f"Peer {fp.id} from {c.Name} failed {job.Action}ed."
|
||||
)
|
||||
@@ -189,6 +189,19 @@ class PeerJobs:
|
||||
)
|
||||
for j in needToDelete:
|
||||
self.deleteJob(j)
|
||||
|
||||
def cleanJob(self):
|
||||
failingJobs = self.JobLogger.getFailingJobs()
|
||||
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.log(job.get('JobID'), Message=f"Job is removed due to being stale.")
|
||||
|
||||
def __runJob_Compare(self, x: float | datetime, y: float | datetime, operator: str):
|
||||
if operator == "eq":
|
||||
|
||||
@@ -395,9 +395,7 @@ class WireguardConfiguration:
|
||||
return changed
|
||||
|
||||
def getPeers(self):
|
||||
tmpList = []
|
||||
current_app.logger.info(f"Refreshing {self.Name} peer list")
|
||||
|
||||
tmpList = []
|
||||
if self.configurationFileChanged():
|
||||
with open(self.configPath, 'r') as configFile:
|
||||
p = []
|
||||
|
||||
@@ -146,8 +146,8 @@ export default {
|
||||
<td v-if="showLogID"><samp class="text-muted">{{log.LogID}}</samp></td>
|
||||
<td v-if="showJobID"><samp class="text-muted">{{log.JobID}}</samp></td>
|
||||
<td>
|
||||
<span class="badge" :class="[log.Status === '1' ? 'text-success-emphasis bg-success-subtle':'text-danger-emphasis bg-danger-subtle']">
|
||||
{{log.Status === "1" ? 'Success': 'Failed'}}
|
||||
<span class="badge" :class="[(log.Status === '1' || log.Status === 'true') ? 'text-success-emphasis bg-success-subtle':'text-danger-emphasis bg-danger-subtle']">
|
||||
{{(log.Status === "1" || log.Status === "true") ? 'Success': 'Failed'}}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{log.Message}}</td>
|
||||
|
||||
Reference in New Issue
Block a user