Wrap _addToDb functionality in a try:except block
This commit is contained in:
parent
e17d03b376
commit
89574d4bbd
@ -141,18 +141,23 @@ def insertSchedule(sch_record):
|
||||
return document
|
||||
|
||||
def _insertToDb(data :list, type :str):
|
||||
if type == "full":
|
||||
mongo.dropCollection("timetable")
|
||||
mongo.putTimetable(data)
|
||||
mongo.createSingleIndex("timetable", "headcode")
|
||||
elif type == "update":
|
||||
for item in data:
|
||||
if item['transactionType'] == "Create":
|
||||
singleList = [item]
|
||||
mongo.putTimetable(singleList)
|
||||
elif item['transactionType'] == "Delete":
|
||||
mongo.deleteTimetableData({'trainUid': item['trainUid']})
|
||||
return True #If Successful else False
|
||||
try:
|
||||
if type == "full":
|
||||
mongo.dropCollection("timetable")
|
||||
mongo.putTimetable(data)
|
||||
mongo.createSingleIndex("timetable", "headcode")
|
||||
elif type == "update":
|
||||
for item in data:
|
||||
if item['transactionType'] == "Create":
|
||||
singleList = [item]
|
||||
mongo.putTimetable(singleList)
|
||||
elif item['transactionType'] == "Delete":
|
||||
mongo.deleteTimetableData({'trainUid': item['trainUid']}) ## Also need to consider the STP indicator and end date here else I am deleting LTP services when an STP is meant to be deleted.
|
||||
return True #If Successfuls
|
||||
except Exception as e:
|
||||
log.out("timetable._insertToDb: Error inserting timetable data", "ERR")
|
||||
log.out(f"timteable._insertToDb: {e}")
|
||||
return False # If error inserting timetable
|
||||
|
||||
def _helpParseStops(schedule_segment):
|
||||
stops = []
|
||||
|
Reference in New Issue
Block a user