forked from oscar.krause/fastapi-dls
implemented endpoint to remove expired leases
This commit is contained in:
parent
7cd4e6fde0
commit
7e5f8b6c8a
@ -186,6 +186,12 @@ async def _leases(request: Request, origin: bool = False):
|
|||||||
return JSONr(response)
|
return JSONr(response)
|
||||||
|
|
||||||
|
|
||||||
|
@app.delete('/-/leases/expired', summary='* Leases')
|
||||||
|
async def _lease_delete_expired(request: Request):
|
||||||
|
Lease.delete_expired(db)
|
||||||
|
return Response(status_code=201)
|
||||||
|
|
||||||
|
|
||||||
@app.delete('/-/lease/{lease_ref}', summary='* Lease')
|
@app.delete('/-/lease/{lease_ref}', summary='* Lease')
|
||||||
async def _lease_delete(request: Request, lease_ref: str):
|
async def _lease_delete(request: Request, lease_ref: str):
|
||||||
if Lease.delete(db, lease_ref) == 1:
|
if Lease.delete(db, lease_ref) == 1:
|
||||||
|
@ -160,6 +160,14 @@ class Lease(Base):
|
|||||||
session.close()
|
session.close()
|
||||||
return deletions
|
return deletions
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete_expired(engine: Engine) -> int:
|
||||||
|
session = sessionmaker(bind=engine)()
|
||||||
|
deletions = session.query(Lease).filter(Lease.lease_expires <= datetime.utcnow()).delete()
|
||||||
|
session.commit()
|
||||||
|
session.close()
|
||||||
|
return deletions
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def calculate_renewal(renewal_period: float, delta: timedelta) -> timedelta:
|
def calculate_renewal(renewal_period: float, delta: timedelta) -> timedelta:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user