Skip to content

Commit

Permalink
Merge pull request #563 from donaldzou/fix-#562
Browse files Browse the repository at this point in the history
Fix #562, and mysterious Jobs disappear issue
  • Loading branch information
donaldzou authored Dec 28, 2024
2 parents aac2a00 + fa4b3ec commit 715a266
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def __createLogDatabase(self):
self.loggerdb.commit()

def log(self, URL: str = "", IP: str = "", Status: str = "true", Message: str = "") -> bool:
pass
try:
with self.loggerdb:
loggerdbCursor = self.loggerdb.cursor()
Expand Down Expand Up @@ -289,7 +288,7 @@ def saveJob(self, Job: PeerJob) -> tuple[bool, list] | tuple[bool, str]:
except Exception as e:
return False, str(e)

def deleteJob(self, Job: PeerJob) -> tuple[bool, list] | tuple[bool, str]:
def deleteJob(self, Job: PeerJob, deletedFrom = 'Job Runner') -> tuple[bool, list] | tuple[bool, str]:
try:
if (len(str(Job.CreationDate))) == 0:
return False, "Job does not exist"
Expand All @@ -299,7 +298,7 @@ def deleteJob(self, Job: PeerJob) -> tuple[bool, list] | tuple[bool, str]:
UPDATE PeerJobs SET ExpireDate = strftime('%Y-%m-%d %H:%M:%S','now') WHERE JobID = ?
''', (Job.JobID,))
self.jobdb.commit()
JobLogger.log(Job.JobID, Message=f"Job is removed due to being deleted or finshed.")
JobLogger.log(Job.JobID, Message=f"Job is removed by {deletedFrom} due to being deleted or finshed.")
self.__getJobs()
return True, list(
filter(lambda x: x.Configuration == Job.Configuration and x.Peer == Job.Peer and x.JobID == Job.JobID,
Expand Down Expand Up @@ -352,9 +351,15 @@ def runJob(self):
f"Peer {fp.id} from {c.Name} failed {job.Action}ed."
)
else:
needToDelete.append(job)
JobLogger.log(job.JobID, s["status"],
f"Somehow can't find this peer {job.Peer} from {c.Name} failed {job.Action}ed."
)
# needToDelete.append(job)
else:
needToDelete.append(job)
JobLogger.log(job.JobID, s["status"],
f"Somehow can't find this peer {job.Peer} from {job.Configuration} failed {job.Action}ed."
)
# needToDelete.append(job)
for j in needToDelete:
self.deleteJob(j)

Expand Down Expand Up @@ -1622,15 +1627,15 @@ def _getWireguardConfigurationAvailableIP(configName: str, all: bool = False) ->

sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False)
sqldb.row_factory = sqlite3.Row
sqldb.isolation_level = None
cursor = sqldb.cursor()

def sqlSelect(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
with sqldb:
try:
cursor = sqldb.cursor()
return cursor.execute(statement, paramters)

except sqlite3.OperationalError as error:
except Exception as e:
print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement)
return []

Expand All @@ -1643,8 +1648,9 @@ def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
s = f'BEGIN TRANSACTION;{statement};END TRANSACTION;'
cursor.execute(statement, paramters)
sqldb.commit()
except sqlite3.OperationalError as error:
except Exception as e:
print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement)
return []

DashboardConfig = DashboardConfig()
_, APP_PREFIX = DashboardConfig.GetConfig("Server", "app_prefix")
Expand Down Expand Up @@ -2299,7 +2305,7 @@ def API_deletePeerScheduleJob():

s, p = AllPeerJobs.deleteJob(PeerJob(
job['JobID'], job['Configuration'], job['Peer'], job['Field'], job['Operator'], job['Value'],
job['CreationDate'], job['ExpireDate'], job['Action']))
job['CreationDate'], job['ExpireDate'], job['Action']), 'API Call')
if s:
return ResponseObject(s, data=p)
return ResponseObject(s, message=p)
Expand Down

0 comments on commit 715a266

Please sign in to comment.