Increase route expiration time

This commit is contained in:
Emmy D'Anello 2023-02-12 23:48:10 +01:00
parent bad5852033
commit f56a280be5
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 2 additions and 1 deletions

3
app.py
View File

@ -36,7 +36,7 @@ class Train(db.Model):
id = Column(String, primary_key=True) id = Column(String, primary_key=True)
day = Column(Date, index=True) day = Column(Date, index=True)
number = Column(Integer, index=True) number = Column(Integer, index=True)
entity = Column(String(10)) entity = Column(String(16))
axe = Column(String(32), index=True) axe = Column(String(32), index=True)
orig_iata = Column(String(5), index=True) orig_iata = Column(String(5), index=True)
dest_iata = Column(String(5), index=True) dest_iata = Column(String(5), index=True)
@ -270,6 +270,7 @@ def process_queue(number: int):
data = resp.json() data = resp.json()
req.response_time = datetime.utcfromtimestamp(data['updatedAt'] // 1000).replace(tzinfo=timezone('UTC')) req.response_time = datetime.utcfromtimestamp(data['updatedAt'] // 1000).replace(tzinfo=timezone('UTC'))
req.expiration_time = datetime.utcfromtimestamp(data['expiresAt'] // 1000).replace(tzinfo=timezone('UTC')) req.expiration_time = datetime.utcfromtimestamp(data['expiresAt'] // 1000).replace(tzinfo=timezone('UTC'))
req.expiration_time += timedelta(hours=3) # By default 5 minutes, extend it to 3 hours to be safe
db.session.add(req) db.session.add(req)
db.session.query(Train).filter_by(day=req.day, orig_iata=req.origin, dest_iata=req.destination)\ db.session.query(Train).filter_by(day=req.day, orig_iata=req.origin, dest_iata=req.destination)\