This commit is contained in:
Fred Boniface
2023-06-01 09:07:57 +01:00
parent f961a18486
commit f8e3c0b8bf
3 changed files with 24 additions and 5 deletions

View File

@@ -186,4 +186,9 @@ def putMetaHash(target :str, hash :str):
def query(collection, query):
col = db[collection]
incrementCounter(collection)
return col.find_one(query)
return col.find_one(query)
def deleteMany(collection :str, filter :dict):
col = db[collection]
incrementCounter(collection)
return col.delete_many(filter)

View File

@@ -96,7 +96,7 @@ def runUpdate():
status = _insertToDb(parsed, required)
if (status):
mongo.metaUpdateTime("timetable")
log.out("timetable.runUpdate: Removing all out of date schedules", "INFO")
_removeOutdatedServices()
## Check what happens if there is no update
def insertSchedule(sch_record):
@@ -181,6 +181,12 @@ def _helpParseDate(string :str, time :str = "false"):
return datetime.strptime(string, "%Y-%m-%d %H%M%S")
def _removeOutdatedServices():
log.out("timetable._removeOutdatedServices: NOT IMPLEMENTED", "WARN")
# Call 'delete' on all services with an end-date $lte today.
return
log.out("timetable._removeOutdatedServices: Removing out of date schedules", "INFO")
preCount = mongo.getLength("timetable")
query = {
"schedule_end_date": {
"$lte": datetime.now()
}
}
postCount = mongo.getLength("timetable")
log.out(f"timetable._removeOutdatedServices: Removed {preCount - postCount} out of date services", "DBUG")